Forum Discussion

todlad52's avatar
todlad52
New Member
3 years ago
Solved

Misnamed column in Power Query

I set up three tiny csv files so that I can combine them using power query in Excel. they are very simple files with column headers named First, Second, Third, Fourth. However, I deliberately made an...
  • Anonymous's avatar
    Anonymous
    3 years ago

    Hi todlad52 ,

     

    In this step, the column names are chosen from the default first file, so there will be no "sceond" column after the expansion.

    You can add a step to get all the column names:

    Replace the previous list.

    Output:

     

    let
        Source = Folder.Files("C:\Users\xxx\Desktop\test"),
        #"Filtered Hidden Files1" = Table.SelectRows(Source, each [Attributes]?[Hidden]? <> true),
        #"Invoke Custom Function1" = Table.AddColumn(#"Filtered Hidden Files1", "Transform File", each #"Transform File"([Content])),
        #"Renamed Columns1" = Table.RenameColumns(#"Invoke Custom Function1", {"Name", "Source.Name"}),
        #"Removed Other Columns1" = Table.SelectColumns(#"Renamed Columns1", {"Source.Name", "Transform File"}),
        Custom1 = Table.ColumnNames ( Table.Combine ( #"Removed Other Columns1"[Transform File] ) ),
        #"Expanded Table Column1" = Table.ExpandTableColumn(#"Removed Other Columns1", "Transform File", Custom1),
        #"Changed Type" = Table.TransformColumnTypes(#"Expanded Table Column1",{{"Source.Name", type text}, {"First", Int64.Type}, {"Second", Int64.Type}, {"Third", Int64.Type}, {"Fourth", Int64.Type}})
    in
        #"Changed Type"

    Best Regards,
    Gao

    Community Support Team

     

    If there is any post helps, then please consider Accept it as the solution  to help the other members find it more quickly. If I misunderstand your needs or you still have problems on it, please feel free to let us know. Thanks a lot!

    How to get your questions answered quickly --  How to provide sample data in the Power BI Forum