Sub topic 5
Combining with Combine & Transform Data
This chapter covers the Combine & Transform Data command, the step that turns a list of files into one table. It assumes you can open the Power Query editor, connect to a folder with From Folder, and filter the file list to the files you want. Those steps come from earlier chapters. You should also know what the Content, Name and Extension columns hold.
What the command does
After you connect to a folder, Power Query shows a preview window with the file list. It has two buttons that matter here:
- Combine & Transform Data builds the combine queries and opens the Power Query editor so you can keep working on the result.
- Combine & Load builds the same queries and loads the result straight to a worksheet. You skip the chance to clean the data first.
If you chose Transform Data instead, you get the raw file list. You can still reach the combine step later by clicking the Combine Files button (the double-arrow icon) at the top of the Content column.
The command does four things:
- It picks the first file in the list as a sample.
- It asks you which part of that file to use, such as a CSV file's contents or a particular sheet.
- It builds a function that turns any one file's
Contentinto a table. - It calls that function on every row of the file list and stacks the results into one table.
Step by step
- Choose Data > Get Data > From File > From Folder.
- Select the folder and click Open.
- Review the file list in the preview window. If it contains files you don't want, click Transform Data, filter the list, and then click Combine Files on the
Contentcolumn. If the list is already correct, click Combine & Transform Data. - In the Combine Files dialog, check the preview of the sample file. For CSV files, you can change File Origin (the text encoding), Delimiter and Data Type Detection here.
- For Excel workbooks, the dialog lists the sheets, tables and named ranges in the sample file. Pick one. The same choice is applied to every file.
- Click OK.
A callout on the choice in step 5 is worth reading before you click.
What you get
Power Query adds several queries and groups them in a folder named after your original query, in the Queries pane. The pane lists them like this:
| Query | Kind | Purpose |
|---|---|---|
| Sample File | Parameter | Holds the one file used as the example. |
| Transform Sample File | Query | Cleans the sample file. Your edits go here. |
| Transform File | Function | Turns any file's `Content` into a table. |
| Parameter1 | Parameter | The argument the function receives. |
| Your folder query | Query | The combined result, which you load. |
The names can differ slightly between Excel versions and between CSV and Excel sources. Chapter 6 covers the helper queries in more detail. For now, the one to remember is that your folder query is the one that produces the final table.
What the combined table looks like
Open your folder query in the editor and look at Applied Steps. You will typically see these steps, with small variations:
- Source: the file list from
Folder.Files. - Filtered Hidden Files1: removes files with the hidden attribute.
- Invoke Custom Function1: adds a column that calls
Transform Fileon eachContentvalue. - Renamed Columns1: renames that new column to
Transform File. - Removed Other Columns1: keeps only the source name column and the transformed column.
- Expanded Table Column1: expands the nested tables into real columns.
- Changed Type: sets column types, based on the first rows it sees.
The first column of the result is Source.Name, which holds the name of the file each row came from. Keep it. It is the simplest way to trace a bad row back to its file.
Where to make changes
This is the most common mistake with the command. Where you edit decides how far the change reaches.
- To change how each file is read, such as removing a header row, renaming a column or filtering rows, edit Transform Sample File. The change flows through
Transform Fileinto every file. - To change the combined table as a whole, such as setting final data types, sorting or adding a column that uses several files' data, edit your folder query.
- Don't edit the
Transform Filefunction directly. It is generated from the sample query, and your edits there can be overwritten.
A worked example
Suppose C:\Data\Sales holds 2026-01.csv, 2026-02.csv and 2026-03.csv. Each has the columns Date, Region and Amount, and each begins with a title line above the header row.
- Connect with From Folder and click Combine & Transform Data.
- In the dialog, keep the delimiter as comma and click OK.
- Open Transform Sample File. You see the title line as the first data row, and the real headers sit in row two.
- In that query, remove the top row with Remove Rows > Remove Top Rows, entering 1, and then use Use First Row as Headers.
- Open your folder query. The combined table now has proper headers from all three files, plus
Source.Name. - Set
Dateto Date,Regionto Text andAmountto Decimal Number. - Click Close & Load.
If you had done step 4 in the folder query instead, only the first file's title line would be removed, and the other two files' title lines would remain as data rows. Editing the sample query avoids that.
Common errors at this step
| Symptom | Likely cause | Fix |
|---|---|---|
| Error in one row: the column of the table wasn't found | One file has a different column name or order | Compare that file with the sample, then fix the file or make the sample query tolerant of the difference |
| Rows with the headers repeated as data | Header promotion was done in the folder query, not the sample query | Move the promotion into `Transform Sample File` |
| Strange first rows from a file named `~$Sales.xlsx` | A temporary file left by an open workbook was included | Filter the file list to exclude names that begin with `~$` |
| Rows from files you did not expect | Subfolders are included by default | Filter on `Folder Path` or remove those files from the folder |
| Garbled characters in text | Wrong **File Origin** for the CSV | Reopen the combine step, or edit the `Csv.Document` call to use encoding 65001 (UTF-8) |
| Error that a sheet or table was not found | The item chosen in the dialog is missing in some files | Make the name consistent across files, or write a custom combine query |
Editing the sample after the fact
The sample file is just a parameter. If you want to test your cleaning steps against a different file, open the Sample File query and change its value to another file in the list. Then check the Transform Sample File preview. This is a good way to check that your steps work for a file that looks different from the first one.
Changing the sample does not change which files are combined. All files in the filtered list are still processed.
Exercise
You combined 12 monthly CSV files. Each file begins with a one-line report title above the header row. The combined table shows the title text as data in 11 of the 12 files. Where did you most likely apply the "remove top row" and "promote headers" steps, and where should you apply them instead?
Show answer
You most likely applied them in the folder query, after the files were already combined, so they affected only the first file's rows. Apply them in Transform Sample File, which feeds the Transform File function and runs once on every file before the tables are stacked.
Exercise
You select the sheet named Budget in the Combine Files dialog, then refresh after a colleague saves a new file whose sheet is named Budget 2026. What happens, and what are two ways to handle it?
Show answer
The refresh returns an error for that file, because the function looks up the sheet by name and cannot find Budget. You can rename the sheet in the new file so the names match, or write a custom combine query that picks the sheet by a rule you control, such as the first sheet or a name that starts with Budget.