Forum Discussion

MarkFlrz's avatar
MarkFlrz
New Member
1 year ago
Solved

Power Query Combine Multiple Files From Folder

Hi community, I'm working on combining 90 excel files from a folder. But the data combined from all files is compiling vertically and I need to change it so I can choose only the columns I need...
  • MasonMA's avatar
    MasonMA
    1 year ago

    Hi, 

    No, you don’t need to add every file name.
    You either keep only columns once in the combined query (applies to all files). Or, if need per-file logic filter on Source.Name patterns instead of listing every single file.

     

    Also instead of “Combine & Transform” you can also manually control it with a few lines of sample M code like below

    let
        // Step 1: Load all files in the folder
        Source = Folder.Files("C:\YourFolderPath"),
    
        // Step 2: Filter only Excel files (if needed)
        ExcelFiles = Table.SelectRows(Source, each [Extension] = ".xlsx"),
    
        // Step 3: Extract tables/sheets from each file
        GetTables = List.Transform(ExcelFiles[Content], each Excel.Workbook(_, true)),
    
        // Step 4: Append everything together
        Combined = Table.Combine(GetTables),
    
        // Step 5: Keep only the columns you want
        Final = Table.SelectColumns(Combined, {"AddressID", "AddressLine1", "AddressLine2"})
    in
        Final