top of page

How to Automatically Combine Multiple Files into One

How to Automatically Combine Multiple Files into a Single Master File in Excel

Many businesses receive monthly sales reports in separate Excel files. Manually combining these files into a single master file each month can be time-consuming and error prone.


Contents:

1. Combining Multiple Excel Files into One

1.1. Folder Setup

1.2. Connecting to the Folder

1.3. Combining Individual Files

2. Helper Queries 3. Transforming Data


Combining Multiple Excel Files into One

We're going to use a built-in tool called Power Query to automate the process of combining multiple files into a single master file. If you've never used Power Query before, don't worry, it's easy!


1. Folder Setup

The first thing we need is one folder and central location to hold all of the individual files that we want to combine.


How to Merge Excel Files, Using Power Query

Create a folder named "Monthly Sales Files" and place all the monthly report Excel files in this folder. It can be anywhere on your computer; in the example it's placed on the desktop.


How to merge multiple Excel files into one

Here are all of the individual files inside of the "Monthly Sales Files" folder.


Ensure each excel file has a consistent structure inside of the workbook. The columns and overall layout of the workbook need to be the same across all reports. If they vary from file to file, you will run into issues combining them.


2. Connecting to the Folder

The next step is to create a connection to the monthly sales folder. Create a new file, I'm calling mine "Combined_Sales" but you can use whatever name you'd like.


Import data from a folder with multiple files (Power Query)

On the new, blank excel sheet, go to the Data ribbon tab > Get Data > From File > and click From Folder.


How to Combine Multiple Excel Files Into One

Then select the "Monthly Sales Files" folder and click "Open". This will launch a window prompting you to combine all of the files found within the selected folder.


3. Combining Files

The next step is to use Power Query to automatically detect and combine the individual files, and pull it into our "master" file.


Excel create master file from individual files

You'll see this window where Power Query displays a list of all files in the folder.


Combine individual excel files into one

Click on Combine & Load


Power Query will prompt you to specify the data to combine. Select the sheet, range, or table, that contains the sales data (e.g., "Sheet1").

Combine data from multiple sheets excel

Power Query will use one file as a "Sample File" and use that file to transform and combine all of the other files. Any changes made to the sample file, will be reflected across all files.


Click OK to combine the data from all files.


Excel combine tables from different workbooks

If there are no errors, then you should see a new sheet was created with all of the data from the individual sheets combined into one table.


The "Queries & Connections" window on the right will also pop up. This gives you an overview of all the queries and different data connections in your workbook and lets you monitor and troubleshoot them.


Helper queries created when combining excel files

A few different files were automatically created. Everything under "Helper Queries" are background functions that facilitate the file combination.


The "Monthly Sales Files" highlighted in green under "Other Queries", is the actual query that is run to combine the files. This is what is loaded and displayed in the workbook.


Understanding the Helper Queries

When you use Power Query to combine files from a folder, it creates several helper queries and functions to automate the process. Here's a breakdown of each component.


Parameter1 (Sample file)

Paramter1 (Sample File) helper query

Acts as a parameter to hold a reference to a sample file from the folder.


This parameter is used by the Transform Sample File query to define the structure and necessary transformations.


Sample File

Sample File helper query

A single file from the folder is used as a representative example.


This file is used to create and test the transformations that will be applied to all other files in the folder. The Sample File query reads the data from this file.


Transform File

transform file helper function

A function generated by Power Query based on the Transform Sample File query.


This function takes a file as input and applies the transformations defined in the Transform Sample File query. It is used to process each file in the folder.


Transform Sample File

transform sample file helper query

Defines the transformations that should be applied to the sample file.


This query includes steps like promoting headers, changing data types, and other transformations. The steps defined here are used to generate a function that applies the same transformations to all files in the folder.


Transforming Data

Once the data is loaded into Power Query, you may need to perform some transformations to clean up and standardize the data.


edit query to merge different files

To edit the query and its output, right click the query under "Other Queries" and press edit. This will launch the Power Query editor.


Some of the most common changes needed are:

  • Promoting column headers and remove top x number of rows

  • Removing unnecessary columns

  • Filtering out empty rows or any unwanted data

  • Ensure data types are consistent and accurate across the columns (e.g., dates, numbers).

Once the data is cleaned and transformed, click Home > Close & Load to load the combined data into a new worksheet in Excel.


The data will automatically update each time new files are added to the folder and the query is refreshed.


To update the query with any added files or changes, click on the table output > Query ribbon tab > Refresh.

refreshing power query to combine multiple files

bottom of page