Sub topic 15
Troubleshooting common problems
This chapter covers the errors that most often appear after a folder query has been working. It assumes you can already build a folder query with Combine & Transform Data, edit the Transform Sample File query, and refresh a loaded table. It also assumes you have read the chapters on file structure and data types.
Most problems fall into three groups. The wrong files are in the list, the files no longer share a structure, or the data types no longer fit the values. Work through them in that order.
A method for diagnosing
Start at the beginning of the query and move forward. Open the Power Query editor and select each step in Applied Steps. Stop at the first step that shows an error or a wrong result.
The order matters because an early problem causes later symptoms. A stray file in the list, for example, can show up as a type error at the end of the query.
Temporary files from open workbooks
When someone opens an Excel workbook, Excel creates a hidden lock file in the same folder. Its name starts with ~$, such as ~$Budget_Jan.xlsx. Folder.Files lists it like any other file.
Power Query cannot read a lock file as a workbook. You typically see an error such as "The file contains corrupted data" or "External table is not in the expected format" in the combined query.
The fix is a filter on the file list. Filter on the Name column so that it does not begin with ~$:
let
Source = Folder.Files("C:\Data\Budgets"),
NoTemp = Table.SelectRows(Source, each not Text.StartsWith([Name], "~$")),
Workbooks = Table.SelectRows(NoTemp, each [Extension] = ".xlsx")
in
WorkbooksIn the editor, use the Name column's filter menu, choose Text Filters, then Does Not Begin With, and enter ~$. Put this filter before the combine step. If the filter comes later, the error has already occurred.
Files from subfolders you did not expect
The From Folder connector includes every file in the chosen folder and in all of its subfolders. An Archive or Old folder inside the source folder therefore feeds its files into the result. The symptom is duplicate rows, totals that are too high, or file names you do not recognize.
Check the Folder Path column in the file list. Each file shows the folder that holds it. To keep only files directly in the source folder, filter Folder Path so that it equals the exact path, including the trailing backslash:
let
Source = Folder.Files("C:\Data\Sales"),
TopLevel = Table.SelectRows(Source, each [Folder Path] = "C:\Data\Sales\")
in
TopLevelA mismatch in the trailing backslash makes the filter return no rows, so compare against the value you see in the column.
Missing columns
The error "The column 'Region' of the table wasn't found" means a step refers to a column by name and one file does not have it. Common causes:
- A file has a renamed header, such as
Regionsorregion. Column names in M are case sensitive. - A file has extra rows above the header, so the first row promoted to headers is not the real header row.
- A file uses a different delimiter or encoding, so the whole row lands in one column.
- A workbook does not contain the sheet you selected.
To find the file that causes the problem, look at the query that Combine & Transform Data created. Select the combined query and look for rows with an Error value in the expanded data. Alternatively, open the function query, Transform File, and invoke it on a single file. The file Name column helps you identify the source.
Once you know the file, decide which side to change. Correcting the source file is simplest when you own it. If you do not, make the query tolerant. For example, select only the columns that exist and tell Power Query to fill the rest with null:
let
Source = Folder.Files("C:\Data\Sales"),
CsvOnly = Table.SelectRows(Source, each [Extension] = ".csv" and not Text.StartsWith([Name], "~$")),
Parsed = Table.AddColumn(CsvOnly, "Data", each Table.PromoteHeaders(Csv.Document([Content], [Delimiter = ",", Encoding = 65001]))),
Safe = Table.AddColumn(Parsed, "Fixed", each Table.SelectColumns([Data], {"Date", "Region", "Amount"}, MissingField.UseNull)),
Combined = Table.Combine(Safe[Fixed])
in
CombinedMissingField.UseNull makes a missing column appear as nulls instead of an error. This hides the problem, so add a check later, such as counting null Region values.
A header that appears as data
If you see the header text as a row in the table, for example a row where Amount equals "Amount", the headers were promoted twice or not promoted in some files. When the sample file has headers on the first row, the function applies the same steps to every file. A file with a title line above the headers breaks that assumption.
Remove any step that promotes headers twice. If some files do have a title line, filter them out or add a step that skips rows before promoting. Table.Skip(table, 1) removes the first row.
Data type errors
A type error appears in a cell as Error with the reason "We couldn't convert to Number" or "DataFormat.Error". It happens when a value in the column cannot be parsed as the chosen type.
Typical causes:
| Cause | Example value | Fix |
|---|---|---|
| Text in a numeric column | `n/a`, `-` | Replace the value with null before setting the type |
| Thousands or decimal separator differs from your locale | `1.234,50` | Use Change Type with Locale and pick the matching locale |
| Date written in another format | `31/12/2026` on a US locale | Change Type with Locale, or parse the text with `Date.FromText` and a culture |
| Trailing spaces or non-breaking spaces | `"100 "` | Apply Trim or Clean, then change the type |
To see which rows fail, select the column, then use Home > Keep Rows > Keep Errors. Read the Name column for those rows to find the file.
Set types after the combine step on the final table, or in the sample file transformation. Avoid setting types on the Content column of the file list, because it is binary.
Changes in the sample file that do not appear
If you edit the sample file query and the result does not change, check which query you edited. Combine & Transform Data created the following queries in a group:
Sample Filereturns one file's binary content.Parameter1holds the sample file.Transform Sample Fileapplies the steps for one file.Transform Fileis the function that the combined query calls.
Put your steps in Transform Sample File. If you add steps directly to the combined query, they apply to the merged result, which is also valid, but a step that depends on one file's layout will not behave the same way. If you delete the first file used as the sample, the generated sample can break. Refresh the sample with a file that still exists.
Refresh problems
A query that works in the editor can fail when you refresh from Excel. Check these:
- The folder path changed. If the folder moved or the drive letter differs on another computer, the Source step fails with "DataSource.NotFound". Update the path, or use a parameter as described in the previous chapter.
- The privacy level blocks combining data. If you see a Formula.Firewall message, open Data > Get Data > Query Options > Privacy and set the level for the project, or set the folder data source to Organizational in the data source settings.
- The file is locked by another program. Close the workbook or copy the files to a staging folder, and read from there.
- The query loaded to a connection only. If the table does not update, check Queries & Connections, right-click the query, and select Load To to confirm the destination is a table.
- Files from a network or cloud drive are not synced yet. Wait for the sync to finish, then refresh.
Slow refresh
The combine step reads every file on each refresh, so cost grows with the number of files. To cut it:
- Filter the file list early, by extension, name pattern, or Date modified, so fewer files are opened.
- Remove columns in the sample file transformation as soon as possible.
- Avoid sorting or merging inside the function that runs per file.
- Move old files into an archive folder outside the source folder.
A checklist before you trust the result
- The Name column lists only the files you expect.
- The row count equals the sum of rows in the source files, minus header rows.
- No cells show Error.
- Types are set, and a sample of values matches the source.
- A test refresh succeeds after you add a new file and after you remove one.
Exercise
A combined query of monthly workbooks fails with "The file contains corrupted data" only when a colleague has one of the workbooks open. What causes this, and what filter fixes it?
Show answer
Excel creates a lock file whose name starts with ~$ in the same folder while a workbook is open. Folder.Files lists it, and Excel.Workbook cannot read it. Filter the Name column with Does Not Begin With ~$ (in M, not Text.StartsWith([Name], "~$")) before the combine step.
Exercise
Your total sales are double what you expect after you create an Old folder inside the source folder. Which column of the file list do you check, and how do you keep only files directly in the source folder?
Show answer
Check the Folder Path column. The connector reads subfolders too. Filter Folder Path to equal the source folder path exactly, including the trailing backslash, such as C:\Data\Sales\.
Exercise
A refresh reports "The column 'Region' of the table wasn't found" for one file out of many. Name two ways to locate the file and one way to make the query tolerant.
Show answer
Find the file by invoking the Transform File function on individual files, or by looking for error rows and reading the Name column. Make the query tolerant by using Table.SelectColumns with MissingField.UseNull, so a missing column becomes null instead of an error. Then add a check so the gap is not hidden.