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

Earn the coveted Fabric Analytics Engineer certification. 100% off your exam for a limited time only!

Reply
janislv
Helper I
Helper I

Expression.Error: The field 'field_name' of the record wasn't found.

I've made several Rest API requests and the addresses are based on date parameters. However, at some periods the records are empty because there is no data to get, so the field of the record is missing. In this case other queries also are affected even if they are completely fine. What is the best method of handling this?

1 ACCEPTED SOLUTION

excellent.  Use try ... otherwise ... in your M code.  If the attempt to access the record fails then you know to ignore that (or do whatever you would do in that case)

View solution in original post

4 REPLIES 4
lbendlin
Super User
Super User

Examine the API response.  You will see subtle differences in the returned data that you can use to your advantage.

 

Here is a particularly harrowing example.  In blatant ignorance of  the web standards the gateway connection status response comes in empty when the connection is good, and returns a proper error message when not.

 

(GatewayId as text, ConnectionId as text) =>
    let
       JsonData = try Json.Document(Web.Contents("https://api.powerbi.com/v1.0/myorg/gateways/" & GatewayId & "/datasources/" & ConnectionId & "/status", [Headers=[Authorization=Authorization]])),
       value = if JsonData[Error][Message]="We reached the end of the buffer." then "True" else "False"
    in
        value

 

So I have to specifically look for an error message "We reached the end of the buffer" to know that the connection is working fine.  Boggles the mind.

This is the response when there is data:

janislv_0-1593810623624.png

 

And this comes when there is no data:

janislv_1-1593810713592.png

excellent.  Use try ... otherwise ... in your M code.  If the attempt to access the record fails then you know to ignore that (or do whatever you would do in that case)

Thanks! I created a table with the existing names of columns for the calculations as result of otherwise. Works fine.

Helpful resources

Announcements
April AMA free

Microsoft Fabric AMA Livestream

Join us Tuesday, April 09, 9:00 – 10:00 AM PST for a live, expert-led Q&A session on all things Microsoft Fabric!

March Fabric Community Update

Fabric Community Update - March 2024

Find out what's new and trending in the Fabric Community.