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

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

Reply
bstock
Frequent Visitor

Handle an error in a custom function

I have a custom function that queries an API for some data and loads it into a table.  I plan on using this function as a column (invoke custom function) to query data from the API based on the usernames in the 1st column.  Now, what I have works so far, but with some username requests to the API, it doesn't return any data.  This is causing an error, and the table stops processing at the first user that kicks out an error when I try to expand the new column.  

 

Is there any way I can handle this better in my query/function so it can keep going, and just creates null data instead of an error? 

 

Hope this makes sense...

 

1 ACCEPTED SOLUTION

PQ will not automatacally handle the errors, by design. What should it do? Replace with null, replace with blank, replace with the word "Error?"

 

The Try/Otherwise construct is exactly for trapping errors and you could use:

try HereIsSomeMath otherwise null

 

and if it gets an error, it will replace with null. It is a good error handler. LIke IFERROR() in Excel. 



Did I answer your question? Mark my post as a solution!
Did my answers help arrive at a solution? Give it a kudos by clicking the Thumbs Up!

DAX is for Analysis. Power Query is for Data Modeling


Proud to be a Super User!

MCSA: BI Reporting

View solution in original post

5 REPLIES 5
flottmen
Frequent Visitor

I know it is a year late but just came across this thread when trying to debug a similar problem.  I found that it works if I expand the columns when I invoke the function rather than in the function itself.  Hope this helps.

bstock
Frequent Visitor

Ok, well I just replaced "errors" with "null" and then expanded the table, and that worked as I had hoped.  However, I'm still curious if there is a way to automate that in the query itself so I can write it into future queries to just kinda handle the errors without having to do anything

 

PQ will not automatacally handle the errors, by design. What should it do? Replace with null, replace with blank, replace with the word "Error?"

 

The Try/Otherwise construct is exactly for trapping errors and you could use:

try HereIsSomeMath otherwise null

 

and if it gets an error, it will replace with null. It is a good error handler. LIke IFERROR() in Excel. 



Did I answer your question? Mark my post as a solution!
Did my answers help arrive at a solution? Give it a kudos by clicking the Thumbs Up!

DAX is for Analysis. Power Query is for Data Modeling


Proud to be a Super User!

MCSA: BI Reporting
edhans
Super User
Super User

Not sure how your custom function looks exactly, but have you tried the:

 

try ... otherwise ...

syntax?

 

There is an article on it here



Did I answer your question? Mark my post as a solution!
Did my answers help arrive at a solution? Give it a kudos by clicking the Thumbs Up!

DAX is for Analysis. Power Query is for Data Modeling


Proud to be a Super User!

MCSA: BI Reporting
bstock
Frequent Visitor

Thanks, I will take a look at that one.  

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

Check out the October 2025 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Kudoed Authors