Smart Systems for Home

Plain how-to guides for smart home, security and home Wi-Fi

Power Query Value.ViewError Function: How to Use It

· 5 min read · Home Tech

In this article
  1. What You'll Need
  2. Step-by-Step
  3. Common Mistakes
  4. Tips
  5. Troubleshooting
  6. Frequently Asked Questions

Value.ViewError is a function in the Power Query M language that returns the text representation of an error record — essentially the same message you would see if you clicked on an error cell in the Power Query Editor. It is mainly used inside custom error handling logic, such as try ... otherwise expressions, custom connectors, or anywhere you want to convert a raw error value into a readable text string. If you have ever caught an error with try and wondered how to turn the resulting error record into a clean message, this is the function that does it.

You need a basic working knowledge of the M language and the Advanced Editor in Power Query (available in Excel and Power BI Desktop). No add-ins or special permissions are required.

What You'll Need

  • Power Query, which is built into modern versions of Excel and Power BI Desktop
  • A query you can experiment on — ideally one that produces an error, such as dividing by zero or reading a missing column
  • Familiarity with opening the Advanced Editor (Home > Advanced Editor in the Power Query Editor; labels can differ slightly between versions)
  • Basic understanding of the try expression and error records in M

Step-by-Step

  1. Open the Power Query Editor. In Excel, go to Data > Get & Transform Data > Launch Power Query Editor, or right-click a query and choose Edit. In Power BI Desktop, click Transform Data on the Home ribbon.

  2. Create or pick a query that produces an error. A simple way is a blank query with:

    let
        Source = 1 / 0
    in
        Source

    This raises a division-by-zero error when evaluated.

  3. Catch the error with try. Wrap the failing expression:

    let
        Result = try 1 / 0
    in
        Result

    When an error occurs, try returns a record with a HasError field and an Error field containing the error record itself.

  4. Apply Value.ViewError to the error record. Modify the query:

    let
        Result = try 1 / 0,
        Message = if Result[HasError] then
            Value.ViewError(Result[Error])
        else
            "No error"
    in
        Message

    Value.ViewError takes the error record and returns its text form, for example something like "Expression.Error: Division by zero". The exact text matches what Power Query would display for that error.

  5. Use the text wherever you need it. Common uses include writing the message into a column, logging it, or substituting it in an otherwise clause:

    try Source[Column1] otherwise Value.ViewError(...)

    Note that otherwise only substitutes a fixed value; to use the actual error text, prefer the try record pattern from step 4.

  6. Test in a table context. Add a custom column that wraps a risky expression in try and pulls the message with Value.ViewError, so failed rows show a readable reason instead of a cell error.

  7. Check the result. Click on the output and confirm you see a plain text message, not an [Error] cell or a raw record.

Common Mistakes

  • Passing the whole try result instead of the error record. Value.ViewError expects the error record (Result[Error]), not the record that try returns (Result). Passing the wrong one causes a type/argument error.
  • Forgetting to check HasError first. If no error occurred, Result[Error] does not exist and accessing it raises a new error. Always branch on Result[HasError].
  • Expecting it to fix the underlying problem. Value.ViewError only formats the error as text; it does not suppress, retry, or repair anything.
  • Confusing it with Error.Record. Error.Record builds a new error record; Value.ViewError displays an existing one.
  • Using it outside a valid context. It is a formatting helper, not a query step you can add from the ribbon — it must be typed in the formula bar or Advanced Editor.

Tips

  • Combine it with try in a custom column to build a "status" column that shows either the computed value or the error message side by side.
  • For cleaner logs, you can also read individual fields of the error record directly, such as the Reason and Message fields, instead of the full formatted text.
  • If you only need to know whether something failed, checking HasError alone is cheaper and simpler than formatting the error.
  • This function is also used internally by Power Query and custom connector diagnostics for rendering error values — knowing it helps when reading connector error-handling code.

Troubleshooting

  • "Expression.Error: The value is not an error record" or a similar message. You likely passed the full try result. Use Result[Error] instead.
  • You get a new error when there was no error. Remove the direct access to Result[Error] and guard it with if Result[HasError] then ... else ....
  • The step shows a raw record instead of text. Make sure Value.ViewError is actually applied to the error record and that you are outputting its result, not the record itself.
  • The error still propagates to the data load. Value.ViewError only formats errors you have already caught with try; uncaught errors elsewhere in the query are unaffected.
  • Older Power Query versions behave oddly. Update Excel or Power BI Desktop to a current version so the function behaves as documented.

Frequently Asked Questions

What does Value.ViewError actually return?

It returns a text value — the printable form of the error record, such as the reason and message, matching how Power Query displays that error in the editor.

Do I need Value.ViewError to handle errors?

No. try ... otherwise handles most error substitution. Value.ViewError is useful when you specifically want the error's text, for example in a log or status column.

Can I use it in a custom column from the ribbon?

Not directly from any ribbon button — there is no UI step for it. Add a Custom Column and type the formula yourself, or use the Advanced Editor.

Is Value.ViewError available in both Excel and Power BI?

Yes. It is part of the shared M language, so it works anywhere Power Query runs, including Excel and Power BI Desktop.

What is the difference between Value.ViewError and Error.Record?

Error.Record creates a new error record with a reason and message; Value.ViewError takes an existing error record and returns its text representation.

Does it change how errors are displayed in the Power Query Editor?

No. The editor's own error display is built in. Value.ViewError simply gives you the same text to use programmatically inside your queries.