Sub topic 15
Troubleshooting common problems
This chapter assumes you can connect to a folder, use Combine & Transform Data, and read basic M code. It covers the errors that appear most often when a folder query is refreshed after files change.
How to approach a failing query
Start with the Applied Steps pane. Click each step in order and find the first one that shows an error or the wrong data. Fix that step, not the last one. Errors in the combined query often start in the Transform Sample File query or in the file list.
Temporary and unwanted files
When a workbook is open in Excel, a hidden lock file starting with ~$ appears in the folder. It is not a real workbook, so combining it fails with an error such as "The file contains corrupt data". Filter these files out before the combine step.
let
Source = Folder.Files("C:\Data\Budgets"),
Real = Table.SelectRows(Source, each [Extension] = ".xlsx" and not Text.StartsWith([Name], "~$"))
in
RealFiles from subfolders
Folder.Files reads every subfolder too. If an Archive folder holds old copies, their rows are added to your result. Filter on the Folder Path column to keep only the folder you want.
let
Source = Folder.Files("C:\Data\Sales"),
TopLevel = Table.SelectRows(Source, each [Folder Path] = "C:\Data\Sales\")
in
TopLevelMissing columns and nulls
A column may be missing or filled with null because one file spells the header differently, for example Amount and amount. Column names in M are case-sensitive. A step that names a column that does not exist fails with "The column 'X' of the table wasn't found".
To find the cause:
- Open the Transform Sample File query and check which file it uses.
- Look at the headers in the file that fails.
- Rename the headers in the source file, or add a rename step that handles both spellings.
If the first row of some files is a title instead of headers, Table.PromoteHeaders takes the title as the column names and the data shifts. Fix the files, or skip the extra rows in the sample file query.
Type errors
If Date or Amount shows Error in some cells, a value could not be converted. Typical causes are text such as "N/A" in a number column, or dates written in a different regional format. Select the column, use Keep Errors to see which rows fail, then fix the source or replace the value with Replace Errors.
Sample file and refresh problems
- If you delete the file the sample query points to, the whole query fails. Keep the sample file in place, or change the sample query to pick the first file in the list.
- If the folder path changes, the query returns a "path not found" error. Update the path, or use the parameter described in the earlier chapter.
- If data does not change after you add files, choose Data > Refresh All. Power Query does not watch the folder.
Quick reference
| Symptom | Likely cause | Fix |
|---|---|---|
| Corrupt data error | `~$` lock file in the list | Filter out names starting with `~$` |
| Extra or duplicate rows | Subfolder files included | Filter on `Folder Path` |
| Column of nulls | Different header spelling | Align header names |
| Error cells in a column | Value cannot convert to the type | Keep Errors, then fix or replace |
| Whole query fails | Sample file deleted or path moved | Restore file or update the path |
Exercise
A combined query worked last month. After a refresh, it fails with "The column 'Region' of the table wasn't found". Name two checks you would make.
Show answer
First, open the files added since the last refresh and check whether the header is spelled or capitalised differently, for example region, or whether a title row comes before the headers. Second, check the file list for unexpected files, such as a ~$ lock file or a file from a subfolder, that does not have the Region column. Then fix the header or filter the file out.