none
Transform Column Names from UPPER to Proper RRS feed

  • Question

  • Hello, 

    Need a little help with figuring out how to transform column names from UPPER to Proper case to capitalize every first letter in my column names. 

    I am transforming my column names to a list and then turning them into a Proper format here: List.Transform(Table.ColumnNames(#"Changed Type"),Text.Proper)   but wrapping it up in Table.TransformColumns() does not work for me and returns an error

    Expression.Error: We cannot convert the value "District Id" to type Function.
    Details:
        Value=District Id
        Type=Type

    Here is my M code. Any ideas what am I doing wrong? 

    = Table.TransformColumns(#"Changed Type", List.Transform(Table.ColumnNames(#"Changed Type"),Text.Proper))

    Monday, May 8, 2017 8:12 PM

Answers

  • The proper way would be using Table.TransformColumnNames:

    let
        Source = Table1,
        RenamedColumns = Table.TransformColumnNames(Source, Text.Proper)
    in
        RenamedColumns

    Tuesday, May 9, 2017 4:05 PM
  • Table.TransformColumns transforms the data in the columns, not the column headers. Here's one method that achieves your goal:

        CurrentColumnNames = Table.ColumnNames(#"Changed Type"),
        NewColumnNames =  List.Transform(CurrentColumnNames, Text.Proper),
        ChangedNames = List.Zip({CurrentColumnNames, NewColumnNames}),
        RenamedColumns = Table.RenameColumns(#"Changed Type", ChangedNames)
    in
        RenamedColumns


    Monday, May 8, 2017 10:45 PM

All replies

  • Table.TransformColumns transforms the data in the columns, not the column headers. Here's one method that achieves your goal:

        CurrentColumnNames = Table.ColumnNames(#"Changed Type"),
        NewColumnNames =  List.Transform(CurrentColumnNames, Text.Proper),
        ChangedNames = List.Zip({CurrentColumnNames, NewColumnNames}),
        RenamedColumns = Table.RenameColumns(#"Changed Type", ChangedNames)
    in
        RenamedColumns


    Monday, May 8, 2017 10:45 PM
  • The proper way would be using Table.TransformColumnNames:

    let
        Source = Table1,
        RenamedColumns = Table.TransformColumnNames(Source, Text.Proper)
    in
        RenamedColumns

    Tuesday, May 9, 2017 4:05 PM
  • Yeah. Completely overlooked that function. Have been using Table.RenameColumns for some stuff recently, so my brain was stuck on this less efficient function for the required task. Thanks for the correction!
    Tuesday, May 9, 2017 4:18 PM