Combine multiple Excel files into one with Power Query

Get the Practice Files

Follow along with the files from the video and build the folder query yourself. Free download.

Key Takeaways

  • Power Query’s From Folder option combines every file in a folder into one table, and new files are picked up on Refresh.
  • Filter the file list before you combine, so only the files you want make it through.
  • Do your cleanup in the sample file wherever you can. Power Query applies those steps to every file before it appends them.
  • Column order doesn’t matter. Column headers must match exactly, including upper and lowercase.
  • You can load the result as a PivotTable or a table, and switch later with Load To.

Why Power Query beats copy and paste

Copy and paste works fine the first time. The trouble starts next month, when the same files come back with new numbers and you’re doing it all over again. VBA can automate it, but then you need to write and maintain the code.

Power Query, on the Data tab under Get & Transform, takes a simpler route. You connect to a folder, set up the steps once, and from then on a refresh pulls in every file in that folder. Even the ones that weren’t there when you built the query.

Connect to the folder

Open a blank workbook and go to Data > Get Data > From File > From Folder. Browse to the folder that holds your files and confirm.

Power Query shows you a list of everything in that folder. If it only held clean files you want, you could click Combine and be done. Most of the time that’s not the case, so click Transform Data instead. That opens the Power Query Editor, where you can filter and clean before anything gets combined.

Filter out the files you don’t need

Folders are rarely tidy. Before you combine anything, filter the file list so only the right files make it through. Two filters cover most cases:

  • Name column: use Text Filters > Contains to keep only files that follow your naming pattern, for example everything with _Data in the name.
  • Extension column: use Text Filters > Begins With and type .xls to keep only Excel files.

The folder connection also picks up files in subfolders, so these filters are your safety net there too.

Combine the files

Click the double-arrow icon at the top of the Content column. Power Query opens the Navigator based on a sample file, which is the first file in your list. Pick the sheet that holds your data and click OK.

Now Power Query does a lot of work for you. It builds transformation steps from that sample file, rolls them out to every other file, and stacks the results into one table. It even adds a filter for hidden files, so a temporary file from a workbook you have open in the background won’t break your query.

In the Queries pane you’ll see a few new helper queries. The one that matters most is Transform Sample File. Anything you do there gets applied to every file before they’re combined.

Clean the sample file, not the combined result

If your source data isn’t in proper Excel tables, the combined result usually needs cleanup. Headers repeat for every file, and empty rows at the bottom of one file show up as null rows in the middle of your data.

You could fix all of that in the final query. But wherever possible, do it in Transform Sample File instead. You fix one file, and every file gets the same fix. Typical steps:

  • Remove Top Rows for anything that sits above the real headers.
  • Use First Row as Headers to promote the headers.
  • Remove Rows > Remove Blank Rows to get rid of the empty rows.

Watch out for the Changed Type step Power Query adds on its own when you promote headers. It doesn’t help you on the sample file side. Delete it there and set data types once, in the final query. Select all columns with Ctrl + A, go to Transform > Detect Data Type, and double-check the result.

When to work in the combined query instead

Some steps can only happen after the files are combined. The file name is the main example. It lives in the Source.Name column of the final query, and it’s often the only place you’ll find information like the company, region or month.

To pull that out, select the column and use Transform > Extract > Text Before Delimiter. Rename the column to something meaningful, and your file names become a proper label column.

Load the result as a PivotTable or a table

Go to Home > Close & Load To. Choose PivotTable Report if you want a summary straight away, or Table if you want the full combined list on a sheet.

You can change your mind later. Right-click the query in the Queries & Connections pane, choose Load To, and pick the other option. Excel checks with you before it removes an existing PivotTable.

Add new files and refresh

This is where the setup pays off. When a new file arrives, drop it into the folder, right-click your PivotTable or table, and choose Refresh. The new data is in.

The order of the columns doesn’t matter. If a new file has the same headers in a different order, Power Query matches them by name and everything lines up.

Headers must match exactly

Column names are a different story. Power Query is case-sensitive, so “Sales Value” and “Sales value” are two different columns. If one file uses the lowercase version, its values won’t show up in the column you’re reporting on. There’s no error. They just go missing.

You have two options. Fix the header in the source file, or, if this keeps happening, have Power Query standardize the headers before the files are combined. In Transform Sample File, click fx next to the formula bar to add a step, and wrap the previous step like this:

= Table.TransformColumnNames(#"Removed Blank Rows", Text.Proper)

Replace #”Removed Blank Rows” with the name of your own previous step. Every header in every file now gets the same capitalization, so they match no matter how they were typed. Add this when you first build the query, so later steps use the new header names.

Set it up once, and next month’s consolidation is a single click.

Download the Workbook

Get the Practice Files

Build the folder query yourself and test the refresh. Free download.

Take It Further

Featured Course

Master Excel Power Query – Beginner to Pro

Power Query is the most underused tool in Excel. Build the monthly cleanup once, then just refresh. One member took a monthly report from 7 days down to 2 hours.
Learn More
Power Query Course cover

Leila Gharani

Founder of XelPlus and ten-time Microsoft MVP. Leila helps over 500,000 professionals master Excel, Power BI, and data automation through practical, real-world training.