Power Query: How to Combine Multiple Workbooks
In this article
To combine multiple workbooks using Power Query, use the Get Data > From File > From Folder path to connect to a directory containing your files, then select the Combine & Transform Data option to merge the tables into a single master list. This process automates the consolidation of data from separate Excel files into one central table, eliminating the need for manual copying and pasting and ensuring that new files added to the folder can be integrated with a single click of the Refresh button.
What You'll Need
- Microsoft Excel (Power Query is built-in for versions 2016 and later; for 2010 or 2013, the Power Query add-in must be installed).
- A dedicated folder on your local drive or network share containing only the workbooks you wish to combine.
- Consistent data structure across all workbooks (the column headers must be identical in spelling and order for the best results).
- The data within the workbooks should ideally be formatted as Excel Tables or located on sheets with identical names.
Step-by-Step
- Organize Your Source Files: Create a new folder on your computer and move all the Excel workbooks you want to combine into this folder. Ensure no other files (like PDFs or unrelated spreadsheets) are in this directory, as Power Query will attempt to process every file it finds in the path.
- Connect to the Folder: Open a new, blank Excel workbook. Go to the Data tab on the ribbon. In the Get & Transform Data group, click Get Data, then select From File, and finally click From Folder. (Note: Menu labels may vary slightly depending on your version of Excel or regional settings).
- Browse to the Directory: A file browser window will appear. Navigate to the folder where you stored your workbooks, select the folder, and click Open.
- Preview and Combine: Excel will display a preview window listing all files found in that folder. Instead of clicking Load, click the dropdown arrow on the Combine button at the bottom of the window and select Combine & Transform Data. This allows you to clean the data before it hits your spreadsheet.
- Select the Object to Combine: The Combine Files dialog box will open. On the left side, you will see a list of the objects inside the workbooks (such as sheets or named tables). Click on the specific sheet name (e.g., Sheet1) or the table name (e.g., Table1) that contains the data. Power Query uses the first file in the folder as a "Sample File" to determine the structure for all other files. Click OK.
- Refine Data in Power Query Editor: The Power Query Editor window will now open. You will notice a new column called Source.Name, which tells you which file each row of data came from. You can keep this for auditing or right-click the column header and select Remove.
- Clean the Data: Perform any necessary transformations. This might include:
- Changing data types (e.g., ensuring date columns are set to Date and currency columns are set to Decimal Number).
- Filtering out null rows or removing unnecessary columns.
- Using Use First Row as Headers if the headers didn't promote automatically.
- Load the Data to Excel: Once the data looks correct, click Close & Load from the Home tab. Power Query will process all files in the folder and load the combined result into a new Excel table in your workbook.
Common Mistakes
One of the most frequent errors is inconsistent naming of headers. Power Query is case-sensitive; if one workbook has a column named "Sales" and another has "sales", Power Query may treat these as two different columns, resulting in a combined table with many empty cells and duplicate columns. Always ensure headers are identical across all source files.
Another common mistake is including the "Master" workbook (the one where you are performing the combination) inside the source folder. If the master file is in the same folder, Power Query will attempt to read the master file as one of the sources, creating a recursive loop that can cause the application to crash or create duplicate data entries.
Users often forget to format their data as Tables (Ctrl+T) within the source workbooks. While Power Query can read sheets, sheets are more prone to "noise" (like random notes written in cells to the right of the data). Tables provide a defined boundary that ensures only the relevant data is captured.
Tips
To make your workflow dynamic, use a network drive or a shared OneDrive/SharePoint folder. This allows multiple team members to drop their individual reports into the folder throughout the month. When it is time to generate the final report, you simply open the master file and click Data > Refresh All to pull in the latest files without repeating the setup process.
If you have a massive amount of data, avoid loading the result directly to a worksheet. Instead, click the arrow under Close & Load and select Close & Load To..., then choose Only Create Connection and check the box Add this data to the Data Model. This stores the data in the background (Power Pivot), allowing you to analyze millions of rows via a Pivot Table without slowing down your Excel interface.
Use the Filter feature on the Extension column in the initial Power Query step to ensure only .xlsx or .csv files are processed. This prevents the query from breaking if a hidden system file (like a temporary owner file starting with ~$) is created by Excel while a source workbook is open.
Troubleshooting
If you receive an error stating that a column was not found, it is almost always due to a change in the source file structure. Check if a column was renamed or deleted in one of the workbooks in the folder. To fix this, go to Data > Queries & Connections, right-click your query, select Edit, and look for the step in the Applied Steps pane (usually "Changed Type" or "Removed Columns") that is causing the error. You can delete that step or update the column name in the formula bar.
If the combined data contains duplicate rows or unexpected blank rows, check the source files for trailing empty rows that might have been formatted as part of a table. You can resolve this in the Power Query Editor by clicking the filter arrow on a primary column and unchecking (null) or (blank).
If the "Combine Files" dialog box does not show the sheet or table you expect, ensure that all files in the folder are of the same file type. Mixing .xls (legacy) and .xlsx files can sometimes confuse the sample file logic. Convert all files to a single format for consistency.
Frequently Asked Questions
Can I combine files from different folders?
The "From Folder" tool only looks at one directory. To combine files from multiple folders, you can either move them into one folder or use a more advanced Power Query technique where you connect to a parent folder and filter the "Folder Path" column to include only the specific subfolders you need.
What happens if I add a new file to the folder later?
You do not need to redo the process. Simply open your master workbook, go to the Data tab, and click Refresh All. Power Query will re-scan the folder, find the new file, and append its data to the bottom of the existing table.
Will this work with CSV files?
Yes, the process is nearly identical. When you select From Folder and then Combine & Transform, Power Query will recognize the CSV format and allow you to specify the delimiter (such as a comma or semicolon) instead of asking you to pick a sheet or table.
Does the order of the files in the folder matter?
By default, Power Query loads files in the order they appear in the directory (usually alphabetical). If the sequence of data is important, ensure your filenames start with a number or date (e.g., 2023-01_Report.xlsx, 2023-02_Report.xlsx) to maintain a logical sort order.
Can I combine workbooks that have different column names?
Yes, but it requires more manual work. You cannot use the automatic "Combine Files" button. Instead, you must create a custom function in Power Query to transform each file individually to a common schema before appending them together.