Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Join the FabCon + SQLCon recap series. Up next: Power BI, Real-Time Intelligence, IQ and AI, and Data Factory take center stage. All sessions are available on-demand after the live show. Register now

Reply
Anonymous
Not applicable

Error Handling (like Try-Catch in SQL)

Hey guys,

 

in my project i have a huge sales dashboard with many data sources and querries (SQL-Database, Web-API, OData-Feed, Excel...). One data source is a excel file. The dashboard is live, important for the sales department in their daily work and is refreshed 3 times per day. I fear huge problems (the whole dashboard could crash?), if anyone changes things in excel (e.g. changing columns or changing the sheets).

 

I know from SQL or Python the error handling method "Try-Catch". My idea was, to implement something like that in the power querry for the excel querry. 

 

Is this possible or do you have any other ideas for this problem?

 

Thanks for your help;)

1 ACCEPTED SOLUTION
BA_Pete
Super User
Super User

Hi @Anonymous ,

 

To do this at the code level in M, you use the try...otherwise structure e.g.

try [Value] / 10 otherwise null

 

To do this at the whole query level you can try these methods:

 

Ensure columns always present:

https://blog.crossjoin.co.uk/2015/07/03/ensuring-columns-are-always-present-in-a-table-returned-by-power-query/ 

 

Handle source qury errors:

https://blog.crossjoin.co.uk/2014/09/18/handling-data-source-errors-in-power-query/ 

 

Make sure to read the comments after each of these blogs carefully, as other users add crucial amendments to the original code.

 

Pete



Now accepting Kudos! If my post helped you, why not give it a thumbs-up?

Proud to be a Datanaut!




View solution in original post

3 REPLIES 3
Anonymous
Not applicable

Thanks to all for your help. This was a great start/input to solve m problems 😉

BA_Pete
Super User
Super User

Hi @Anonymous ,

 

To do this at the code level in M, you use the try...otherwise structure e.g.

try [Value] / 10 otherwise null

 

To do this at the whole query level you can try these methods:

 

Ensure columns always present:

https://blog.crossjoin.co.uk/2015/07/03/ensuring-columns-are-always-present-in-a-table-returned-by-power-query/ 

 

Handle source qury errors:

https://blog.crossjoin.co.uk/2014/09/18/handling-data-source-errors-in-power-query/ 

 

Make sure to read the comments after each of these blogs carefully, as other users add crucial amendments to the original code.

 

Pete



Now accepting Kudos! If my post helped you, why not give it a thumbs-up?

Proud to be a Datanaut!




Ben Gribaudo also has a valuable article on error handling.

 

https://bengribaudo.com/blog/2020/01/15/4883/power-query-m-primer-part-15-error-handling

Helpful resources

Announcements
April Power BI Update Carousel

Power BI Monthly Update - April 2026

Check out the April 2026 Power BI update to learn about new features.

New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

FabCon and SQLCon Highlights Carousel

FabCon &SQLCon Highlights

Experience the highlights from FabCon & SQLCon, available live and on-demand starting April 14th.