
Combining Excel files in Microsoft Power Query does not have to create any helper queries. Excel’s data-preparation option can bring matching tables together or reshape budgets with months spread across columns before combining them. You can also use code generated by the menus as a starting point, rather than writing every transformation from scratch. Understand how to apply those transformations to the tables inside each workbook as Excel Off The Grid walks through both approaches to combining files.
Power Query: Combine Files in One Folder Query
TL;DR Key Takeaways :
- Power Query can read workbooks from a folder using Excel.Workbook and combine their data within one query, without helper queries.
- For files with matching layouts, Table.Combine stacks nested tables without selecting individual columns.
- After stacking the stock files, promote the first header row and filter out the repeated headers.
- For the three cross-tab Budget files, promote headers and unpivot month columns inside each nested table before combining them.
- You can let the menus generate the code for a step, copy it, then apply it to each nested table with Table.TransformColumns.
You can combine files from a local folder in Microsoft Power Query while keeping the transformations in one folder query. Power Query records data preparation as editable steps that run again when you refresh the query. In Excel, the feature is known as Get & Transform.
The standard Combine Files command asks you to choose a sample file and drills into it to promote its headers. It creates a sample-file query and a function, then applies that function to the files before stacking their data. The alternative keeps the transformations in the folder query instead of creating helper queries, making it easier to see what happens to the files.
Open the Folder and Read Each Workbook
Start with a folder query, but leave the double-down-arrow Combine Files control unused. Instead, add a column to read each workbook’s contents.
- Right-click the queries pane and select New Query > File > Folder.
- Choose the folder, click Open, then select Transform Data.
- Select Add Column > Custom Column and name the new column Excel.
- Enter the expression below and click OK.
The Excel.Workbook function takes a binary value, supplied here by the folder query’s Content column:
Excel.Workbook([Content])
Remove the other columns, expand the new Excel column and clear Use original column name as prefix. Power Query will list the worksheets inside the workbooks. If a workbook contains more than one sheet, you can filter the list to the sheets you need. For the layouts below, keep the Data column and remove the others.
Here are more detailed guides and articles that you may find helpful on excel automation tips.
- How to create Excel spreadsheets that automatically update themselves
- Excel automation tips to save you time in 2024
- Master Excel Automation : Save Hours with These Simple Tricks
- Excel Automation Guide 2025 : Say Goodbye to Spreadsheet Stress
- Easy to Setup Excel Automations to Save Time Everyday
Stack Files With Matching Layouts
A simpler approach works when the files already have a consistent, useful row structure.
In the stock-folder example, the three files each have one header row, their columns appear in the same order, and there are no unwanted rows above the headers. The data is in first normal form.
You could expand the Data column directly, but that operation records the selected column names in the formula bar. In the example, it selects columns 1 through 9, so the expansion is tied to those nine columns.
Instead, select the FX icon to add a step using Table.Combine, and supply the Data column from the previous step as the list of tables. The function stacks those tables into one result without selecting the nine columns individually.
Remove Repeated Header Rows
Stacking the stock files also stacks their headers. In the example, those rows appear at positions 1, 22 and 43 in the combined data.
Select Home > Use First Row as Headers to turn the first row into column names. Then filter the Date column to remove the remaining rows whose value is “date”. The result combines the three files in one query without the standard helper queries.
Promote Headers Inside Each Nested Table
A different layout needs transformations before you combine the tables. The three Budget files use a cross-tab layout, with months across columns and a different year in each file. For example, column 4 contains April 30, 2021 in one workbook and April 30, 2022 in another. You therefore need to promote the headers and unpivot the data before combining the files.
Create the folder query and workbook column as above, leaving the nested tables in Data. To get the header-promotion code, temporarily select Use First Row as Headers, copy the formula from the Promoted Header step and delete the temporary steps, including the automatically added Change Type step.
Add a step with the FX icon and use Table.TransformColumns to apply the copied Table.PromoteHeaders transformation to the Data column. Supply the preceding step as the first argument, use each for the row-by-row operation and replace the copied formula’s previous-step reference with an underscore. The outer table can look unchanged; click into a Data cell to see the promoted headers inside its nested table.
Unpivot the Tables Before Combining Them
The Budget files also need their month columns turned into rows. Power Query can generate the unpivot code through its interface, which you can then adapt to run inside each nested table.
Return temporarily to a step with more than one column, right-click the Name column and choose Unpivot Other Columns. Copy the generated Table.UnpivotOtherColumns formula and delete the temporary unpivot step.
After the header-promotion step, add another Table.TransformColumns step for Data, using each and replacing the copied previous-step reference with an underscore. The generated formula initially refers to Name, which produces an error. Change the retained columns to account code, account and cost center, the columns in the nested tables, and change the output column name from Attribute to Date. Type those names exactly as they appear in your files, because Power Query’s M formula language is case-sensitive. Expand the resulting tables without the original column-name prefix to combine their rows.
Excel can then load the combined data into a worksheet or the workbook’s Data Model. A worksheet holds up to 1,048,576 rows when loading data from Power Query.
For us, the real gain is a single query you can read from top to bottom. When every step sits in one place, we think it is easier to see what happens to your files than when the logic is spread across several linked queries. Before you rely on this, we would check that every file really has the same layout. Because the steps are written by hand into one query, a file with a different column order or an extra sheet could quietly give wrong results.
Your experience with Power Query’s menus can be a starting point for writing M transformations, since the interface supplies code you can adapt for nested tables. If you collect Excel workbooks for recurring reports, combining files in a single Power Query folder query is a method well worth trying.
Media Credit: Excel Off The Grid
Disclosure: Some of our articles include affiliate links. If you buy something through one of these links, Geeky Gadgets may earn an affiliate commission. Learn about our Disclosure Policy.