Search code examples
powerquerycamelcasingm

Convert String AnyName into Camelcase


I'm working for a while with Microsoft Power Query M and I have the situation that I need to transform names in the first column into Camelcase.

I receive the data in form Any_Name. First step I do is to replace _ by "":

 #"Replaced Value" = Table.ReplaceValue(#"Expanded {0}","_","",Replacer.ReplaceText,{"Column1.dbColumnName"})

The output of the above function for each cell in the first colum is AnyName and I need now to transform the first char into a lowercase character to have a Camelcase String.

How is it possible to do so? Since there is no function for it. I was thinking about to take the first char by splitting the Text with Text.Split. This function does only allow the splitting at the desired character. But not at the number of the character. So it is not possible to say split at charpos 0. The transformation into upper case shall be done with Text.Upper. The usage of Text.PadStart could be used to add the transformed char again.

My problem is that I do know how to apply this on all cells in the first column.


Solution

  • You can use

    let
        Source = #table(type table[Name = text],{{"MarcelBeug"},{"IrgendwPointer"}}),
        camelCase = Table.TransformColumns(Source,{"Name", each Text.Lower(Text.Start(_,1))&Text.Range(_,1)})
    in
        camelCase