Forum Discussion

dataPhix's avatar
dataPhix
Frequent Visitor
5 years ago
Solved

Power Query: Include all unique columns found in files from folder

I've recently run into an issue which hopefully is solvable. Currently, I have power query pointing at a folder containing several CSV files. This is normally no issue, however, in this instance n...
  • Fowmy's avatar
    Fowmy
    5 years ago

    dataPhix 

    Can you paste this code and follow the steps to check if it works for you?
    Enter your folder path

    let
        Source = Folder.Files("C:\xx\xx"),
        #"Removed Other Columns" = Table.SelectColumns(Source,{"Content", "Name"}),
        #"Added Custom" = Table.AddColumn(#"Removed Other Columns", "Custom", each Table.PromoteHeaders(Csv.Document([Content]))),
        Custom1 = Table.Combine({#"Added Custom"},{"Name", "Custom"}),
        #"Sorted Rows" = Table.Sort(Custom1,{{"Name", Order.Descending}}),
        #"Expanded Custom" = Table.ExpandTableColumn(#"Sorted Rows", "Custom", {"one", "two", "yes", "no", "may be", "three", "four"}, {"one", "two", "yes", "no", "may be", "three", "four"}),
        #"Reordered Columns" = Table.ReorderColumns(#"Expanded Custom",{"Name", "one", "two", "three", "four", "yes", "no", "may be"}),
        #"Sorted Rows1" = Table.Sort(#"Reordered Columns",{{"Name", Order.Ascending}})
    in
        #"Sorted Rows1"

    ________________________

    If my answer was helpful, please consider Accept it as the solution to help the other members find it

    Click on the Thumbs-Up icon if you like this reply 🙂

    YouTube  LinkedIn