Error.Record
Creates an error value with a reason, a message and detail, which you raise with the error keyword.
Error.Record(reason, optional message, optional detail)Returns: An error record. Use it with the error keyword to stop a step and explain why.
What it does
Error.Record builds an error that you can throw on purpose. Normally Power Query raises errors for bad data, such as a text value that cannot be converted to a number. Error.Record lets you raise your own, with a clear reason, so that a failed control check stops the refresh with a message a reviewer can act on. It is paired with the error keyword, which is described on its own page.
Syntax and arguments
reason: a short text label for the error, such as "Control total mismatch".message(optional): a sentence explaining what happened.detail(optional): any value with more information, such as the difference in amount or a list of the failing rows.
Example
A bank load should contain at least one transaction. If the file is empty, the refresh should stop with a message rather than produce a report with zero totals.
let
Source = Csv.Document(File.Contents("C:\Banking\statement-2026-03.csv"), [Delimiter = ","]),
Checked = if Table.RowCount(Source) = 0
then error Error.Record("Empty file", "The bank file has no transaction lines.", "Check the export before you continue.")
else Source
in
Checked
When the file has rows, the query returns the table unchanged. When it is empty, the refresh stops with the reason "Empty file" and the message shown.
Example: a second, different use
Raising an error for a control total that does not agree, with the difference in the detail field so the reviewer can see the size of the gap.
Things to watch
- The reason is the short label people see first. Keep it consistent across checks, so they can search for it.
- Error values stop the step they are in. Use them for real failures, not for every unusual value.
- An error that you raise can be caught with try, so decide whether a downstream step should catch it.
- Table.RemoveRowsWithErrors and Table.ReplaceErrorValues act on errors that already exist in data. They do not change what Error.Record raises.
In business terms
Control checks that stop a load, such as an empty file, a total that does not agree or a missing period, are a basic control in a close. A clear error message is evidence that the check ran.