Error Handling
Excel deals with errors in a formula through IFERROR, which returns a fallback value when the first argument fails:
= IFERROR(value, value_if_error)
Power Query has no IFERROR function. It uses the keywords try and otherwise instead, and it can also report why each error happened. This page works through both, using a small price table in which some prices are Excel errors:

The aim is a new SubTotal column that multiplies [Price] by [Amount]. Where the price is an error, the calculation should fall back to [List Price] instead.
1. Load the table as a query
Section titled “1. Load the table as a query”Once the table is loaded into Power Query, each Excel error appears as the word Error in the Price column:

2. Add a custom column with try and otherwise
Section titled “2. Add a custom column with try and otherwise”On the Add Column tab, choose Custom Column, name the column SubTotal, and enter a formula that tries the price first and falls back to the list price:
![The Custom Column dialog with the new column named SubTotal and the formula try [Price][Amount] otherwise [List Price][Amount]](/_astro/error-handling-3.It5zx0NX_2re9nw.webp)
Power Query evaluates the expression after try. If it succeeds, its result is used, and if it fails, the expression after otherwise is used instead. Every row now has a subtotal:

3. Find out what caused each error
Section titled “3. Find out what caused each error”A fallback hides the error, which is not always what is wanted. To see why each price failed:
- Remove the Changed Type step from Applied Steps.
- Add another custom column, called Error Message, holding
tryon its own, with nootherwise:
![The Custom Column dialog with the new column named Error Message and the formula try[Price]](/_astro/error-handling-5.Cu37aPZ5_fQPYh.webp)
tryon its own returns a record for each row. Click the expand button on the column header and keep all three of its fields:

The table now shows whether each row failed. A good row has HasError set to FALSE and its price in Value, while a failed row has HasError set to TRUE and a record in Error:

- Expand the Error column in turn, keeping Reason and Message, and then remove the HasError and Value columns:

The finished table gives the cause of each error beside the row it affects:

Using HasError in M
Section titled “Using HasError in M”When the expression after try succeeds, the record it returns has HasError set to false, and Value holds the result:

Because the record can be tested like any other, errors can be handled in M without otherwise. The query below keeps the try record in a column, and then takes the value where there was no error and null where there was:
let Source = Excel.CurrentWorkbook(){[Name="Sample"]}[Content], #"Added Custom" = Table.AddColumn(Source, "Record", each try[Price]), #"Added Custom1" = Table.AddColumn(#"Added Custom", "Price.1", each if [Record][HasError] then nullelse [Record][Value])in #"Added Custom1"The result is the same as writing try [Price] otherwise null, which returns null wherever the price is an error.
An error can also be replaced with one that carries a message of your own, so that whoever sees it knows what went wrong:
let Source = Excel.CurrentWorkbook(){[Name="Sample"]}[Content], #"Added Custom" = Table.AddColumn(Source, "Record", each try[Price] otherwise error "Price is invalid")in #"Added Custom"