Analistable

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

Queries generated by Combine Files
QueryPurpose
Sample FileThe file used as the example (the first by default)
Parameter1Points the function at a file
Transform Sample FileYour steps — edit this to change every file
Transform FileThe function applied to each file (don't edit directly)
Your folder queryLists 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

  1. Put the files in one folder. Subfolders are included too.
  2. Data → Get Data → From File → From Folder, choose the folder.
  3. Click Combine → Combine & Transform Data.
  4. Pick the sheet or table (Excel) or check delimiter and encoding (CSV) in the Combine Files dialog. Click OK.
  5. 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 ~$.
  6. 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 like sales_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

Common errors
ErrorCauseFix
The key didn't match any rows in the tableA file lacks the sheet name used in the sampleUse Source{0}[Data] or rename the sheet
The column 'X' of the table wasn't foundA Changed Type step references a column missing in a fileRemove the column from that step or add MissingField.Ignore
DataFormat.ErrorA value can't convert to the column typeReplace errors, or change type later
Duplicated rowsThe output file is saved in the same folderSave 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.

Related guides