cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
New Member

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

Accepted Solutions
Highlighted
Super User V
Super User V

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

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
Highlighted
Super User V
Super User V

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

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.

Highlighted
New Member

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

This is the response when there is data:

janislv_0-1593810623624.png

 

And this comes when there is no data:

janislv_1-1593810713592.png

Highlighted
Super User V
Super User V

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

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

Highlighted
New Member

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

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

Helpful resources

Announcements

August Community Highlights

Check out a full recap of the month!

August 2020 CYST Challenge

Check out the winners of the recent 'Can You Solve These?' community challenge!

Experience what’s next for Power BI

Join us for an in-depth look at the new Power BI features and capabilities at the free Microsoft Business Applications Launch Event.

Top Solution Authors
Top Kudoed Authors