How to combine files from a folder with Power Query
By the Analistable team · Updated · 2 min read
Choose Data → Get Data → From File → From Folder (Power BI: Get data → Folder), select the folder and click Combine & Transform Data. Power Query uses the first file as a sample, records your steps in a Transform Sample File query, applies them to every file through a generated function, and stacks the results with a Source.Name column. Edit the sample query to change how every file is processed.
Part of our guide: How to merge data in Power BI, Power Query and Tableau
What Power Query creates
| Query | Purpose |
|---|---|
| Sample File | The file used as the example (the first by default) |
| Parameter1 | Points the function at a file |
| Transform Sample File | Your steps — edit this to change every file |
| Transform File | The function applied to each file (don't edit directly) |
| Your folder query | Lists the files, calls the function, expands the results |
The key idea: changes made in Transform Sample File (promote headers, remove top rows, change types) apply to every file on refresh.
Step by step
- Put the files in one folder. Subfolders are included too.
- Data → Get Data → From File → From Folder, choose the folder.
- Click Combine → Combine & Transform Data.
- Pick the sheet or table (Excel) or check delimiter and encoding (CSV) in the Combine Files dialog. Click OK.
- In the main query, filter the Extension column (for example to
.xlsx) and the Name column to exclude files you don't want — such as temporary files starting with~$. - Fix column types in Transform Sample File, then Close & Load.
Useful changes
- Take the first sheet whatever its name: in Transform Sample File, change the navigation step to
Source{0}[Data]. - Keep every column from every file: replace the final expand step with
Table.Combine(PreviousStep[Transform File])— the default expand only keeps the sample file's columns. See combining files with different columns. - Parse dates from the file name: add a custom column on Source.Name, such as
Date.FromText(Text.Middle([Source.Name], 6, 10))for names likesales_2026-09-30.csv. - Files on SharePoint: use From SharePoint Folder with the site URL, then filter the Folder Path column.
Refresh errors and fixes
| Error | Cause | Fix |
|---|---|---|
| The key didn't match any rows in the table | A file lacks the sheet name used in the sample | Use Source{0}[Data] or rename the sheet |
| The column 'X' of the table wasn't found | A Changed Type step references a column missing in a file | Remove the column from that step or add MissingField.Ignore |
| DataFormat.Error | A value can't convert to the column type | Replace errors, or change type later |
| Duplicated rows | The output file is saved in the same folder | Save the result elsewhere or filter its name out |
Want the simple version first? See combining Excel files into one spreadsheet or, for CSV, combining CSV files in Excel.
Frequently asked questions
- How do I combine all files in a folder in Excel?
- Use Data → Get Data → From File → From Folder, then Combine & Transform Data. Every file in the folder is stacked into one table.
- How do I change the steps applied to every file?
- Edit the Transform Sample File query. Its steps are applied to each file through the generated function.
- Can Power Query combine files from SharePoint?
- Yes, with Get Data → From SharePoint Folder, filtered to the folder path you need.