Sub topic 10
Combining many files with the same layout into one table
This chapter assumes you can open Power Query Editor, read the Applied Steps pane, and connect to a single CSV or Excel file. It also assumes you know what a table, a column, and a data type are. Here you will turn a folder of files with the same layout into one table.
When to combine files
Suppose a system exports one CSV per month: orders-2026-01.csv, orders-2026-02.csv, and so on. Every file has the same columns. You want one Orders table, not twelve queries.
Power Query handles this with the Folder or SharePoint Folder connector. These connectors return one row per file, not the contents of the files. The Combine command then reads each file with the same steps and appends the results.
How Combine works
When you choose Combine & Transform Data, Power Query creates several objects for you:
- A sample file query that holds one file as a model.
- A function query (for example
Transform File) that applies the sample file's steps to any file. - A helper query group that keeps these pieces together.
- Your main query, which calls the function on every file and expands the results.
The key point is that the function is built from the sample file. If you fix a step in the sample (for example, a data type), every file gets the fix.
Worked example
Connect to the folder that holds the CSV files. For SharePoint Online, use Get Data > SharePoint Folder and enter the site URL, not the full folder URL. For local files, use Get Data > Folder.
You get a table with columns such as Content, Name, Extension, and Folder Path. Filter it before combining, so stray files do not break the result:
let
Source = SharePoint.Files("https://contoso.sharepoint.com/sites/Sales", [ApiVersion = 15]),
InFolder = Table.SelectRows(Source, each [Folder Path] = "https://contoso.sharepoint.com/sites/Sales/Shared Documents/Orders/"),
OnlyCsv = Table.SelectRows(InFolder, each [Extension] = ".csv")
in
OnlyCsvThen choose Combine & Transform Data on the Content column. In the dialog, pick the sample file and confirm the delimiter and encoding. Power Query builds the helper queries and returns one table with a Source.Name column that records each row's file.
Finally, set data types in the combined query. Do this once, after the append, and check that OrderDate is a date and Amount is a number.
Common errors
| Symptom | Likely cause | Fix |
|---|---|---|
| Error cells in some rows | A file has a different column count or order | Move the odd file out, or fix the export |
| Missing data from some files | The folder filter or extension filter excludes them | Check the `Extension` and `Folder Path` filters |
| Header rows appear as data | A file has no header, or headers were promoted twice | Promote headers inside the transform function only |
| Combine fails after a new file arrives | The new file has a different layout or is a temp file such as `~$orders.xlsx` | Filter by extension and name |
| Wrong characters | Sample file encoding differs from other files | Set the encoding in the sample file query |
Habits that keep it stable
- Filter the file list by folder path and extension before combining.
- Edit steps in the sample file query or the function, not in the main query, when the fix should apply to every file.
- Use a parameter for the folder location so you can switch sites or folders without editing steps.
Exercise
You combine twelve monthly CSV files. The result shows null values in the Amount column for every row from March only. All other months are fine. What is the most likely cause, and where do you check first?
Show answer
The March file likely uses a different column name or layout (for example "Total" instead of "Amount"), so the function finds no matching column and returns null. Open the March file, compare its header row with the sample file, and fix the export or rename the column in the transform function.