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
Meet the 2020 Season 2 Power BI Super Users!

Meet the 2020 Season 2 Power BI Super Users!

Find out who's part of the program this season, and welcome the new Super Users.

August 2020 Community Challenge: Can You Solve These?

August 2020 Community Challenge: Can You Solve These?

We're excited to announce our first cross-community 'Can You Solve These?' challenge!

July 2020 Community Highlights

July 2020 Community Highlights

Learn about the exciting things that happened in July.

Featured Data Story of The Month

Featured Data Story of The Month

All Data Stories Gallery contributions are reviewed for each month. We select a contribution and feature the community member the following month.

Power BI Dev Camp - Developing with .NET Core

Power BI Dev Camp - Developing with .NET Core

Learn how to develop custom web applications for Power BI using .NET Core 3.1 and .NET 5.

Top Solution Authors
Top Kudoed Authors