Downloads
Power Query MErrors and typesAdvanced

Error.Record

Creates an error value with a reason, a message and detail, which you raise with the error keyword.

Syntax
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

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

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.

Related functions

All Power Query M functions · View as Markdown · M basics