Power Query Excel Error Logging: A How-To Guide
In this article
To log errors from Power Query in Excel, you need to capture them before they break the refresh. The most reliable method is to add a custom column that tests each row with try ... otherwise, records the error reason in a text column, and then filters or outputs that log to a table. This guide walks through building a reusable error-logging pattern, step by step, using only built-in Power Query features. No add-ins are required, but you should be comfortable with the Power Query Editor and basic M code.
What You'll Need
- Excel 2016 or later (Power Query is built in as Get & Transform).
- A data source you can connect to (workbook table, CSV, database, etc.).
- Basic familiarity with the Power Query Editor: adding columns, writing simple M expressions, and loading queries to a worksheet.
Step-by-Step
- Load your source into Power Query. Select your data and use Data > From Table/Range (or the appropriate connector). This opens the Power Query Editor. Menu labels can differ slightly by Excel version and region.
- Profile your columns first. On the View tab, enable Column Quality and Column Distribution. This shows how many valid, empty, and error values exist per column, so you know where errors are likely.
- Add a custom column to capture errors. Go to Add Column > Custom Column. Name it something like
ErrorLog. In the formula box, use a try expression that references the column most likely to fail, for example:try [Amount] otherwise "Error: " & (try [Amount] otherwise error)[Message]. A simpler and more robust pattern is to wrap the whole row:try [Amount] otherwise nulland then check for nulls separately. - Create a dedicated error-reason column. Add another custom column,
ErrorReason, with:try [Amount] otherwise error[Message]. This returns the error message text when the conversion fails, and the original value when it succeeds. You can then filter this column to keep only rows where the value starts with "Error" or is not null. - Separate good rows from bad rows. Duplicate the query (right-click the query in the Queries pane > Duplicate). In the first copy, filter out rows where
ErrorReasoncontains an error message. In the second copy, keep only those rows. Rename them clearly, e.g.,CleanDataandErrorLog. - Expand the error details if needed. If you used
try ... otherwiseon a record, the result is a record withHasError,Error, andValuefields. Use the expand icon to extractError.ReasonandError.Messageinto separate columns for clearer logs. - Load both queries to the workbook. Close & Load To... and choose Table for each. Place
CleanDataon your working sheet andErrorLogon a separate sheet named "Error Log". This keeps the log visible without disrupting your analysis. - Refresh and verify. Use Data > Refresh All. Check that the Error Log table populates with the expected rows and that CleanData excludes them. If the log is empty, confirm your try expression references the correct column name (case-sensitive in M).
- Optional: add a timestamp. In the ErrorLog query, add a custom column with
DateTime.LocalNow()so each refresh records when the error was captured. Note this updates on every refresh, not historically.
Common Mistakes
- Using try on the wrong column. The error often originates in a step like Changed Type, not the raw column. Wrap the step's expression, not just the column reference.
- Forgetting that try returns a record. If you don't expand or otherwise-handle the result, you'll see "Record" in the cell instead of a value or message.
- Filtering before logging. If you remove error rows early, the ErrorLog query has nothing to capture. Always duplicate the query before filtering.
- Assuming the log persists. Power Query output is refreshed, not appended. Each refresh replaces the table; it is not a historical audit trail unless you copy values elsewhere.
- Case and space mismatches. Column names in M are case-sensitive and must match exactly, including spaces.
Tips
- Use
try ... otherwiseat the row level to catch multiple column errors in one pass:try Record.Field(_, "Amount") otherwise null. - Keep the ErrorLog query lightweight: select only the key columns plus the error message to avoid bloating the workbook.
- Name steps descriptively in the Applied Steps pane so you can trace where an error was introduced.
- For recurring refreshes, consider loading the ErrorLog to the Data Model (Power Pivot) so you can analyze error patterns over time with measures.
- Document the expected data types in a comment or a separate documentation sheet; most errors come from type mismatches.
Troubleshooting
If the ErrorLog table is empty after refresh, first check that the source actually contains errors by using Column Quality. If errors exist but aren't captured, verify the try expression references the exact column name and that you haven't filtered them out earlier. If you see "Record" instead of a message, expand the column or use error[Message] directly. If refresh fails entirely, the error is likely in a step before your try expression; use the Applied Steps pane to step through and identify the failing step. If the workbook becomes slow, reduce the number of columns in the ErrorLog query and avoid loading large error tables to the worksheet. Finally, if the log shows errors that don't appear in the source preview, refresh the preview and check for data type changes applied by Excel automatically.
Frequently Asked Questions
Can I log errors without duplicating the query?
Yes, you can add a conditional column that flags errors and then use that flag to filter in a separate query that references the original. Duplicating is simpler and avoids complex dependencies.
Does the error log update automatically?
It updates when you refresh the query. It does not append historical entries; each refresh replaces the table with the current errors.
Why does my try expression return a record instead of a value?
Because try returns a record with HasError, Error, and Value fields. Use otherwise to provide a fallback, or expand the record to extract the message.
Can I capture the step name where the error occurred?
Not directly. Power Query does not expose step names in error records. You can approximate by wrapping individual steps in try and adding a static label column.
Is there a built-in error logging feature?
No. Power Query has no native error log; the try/otherwise pattern is the standard workaround.
Will this work in Excel for Mac?
Yes, the Power Query Editor and M functions are the same, though menu locations may differ slightly.