Efficient API Calls in Power BI: Using Open API Data fixing Power BI dataset error with Web.Contents()
John Basha
9x Microsoft Certified | Fabric Super User | Power BI Developer, Architect??? ?? | DAX | MSBI | T-SQL | Azure SQL, Data bricks, Synapse ?, Data Factory | Tabular SSAS | SSRS | SAP Hana | ?? Data Story teller ???
When working with Power BI, efficiently retrieving data from APIs is crucial for performance and reliability, particularly when handling large datasets. This guide examines two different approaches to fetch data from the NHS UK API and explains why one method is more effective after publishing the dataset.
Scenario
You are tasked with fetching incident data from the NHS UK ServiceDesk API, specifically from the incident table. The API endpoint is https://servicedesk.NHS.UK.gov.com/api/now/table/incident.
I am sure some of you might have faced/come across with the error below when you are trying to connect to any API in Power Query.
I have got a solution for you. :) ;)
Approach 1: Ineffective After Publishing
Let's look at the first approach, which does not work reliably after publishing the dataset:
Approach 2: Effective After Publishing
Here's the improved approach that works effectively after publishing:
Key Differences and Advantages of the Second Approach
1. URL Construction
First Approach:
FullUrl = BaseUrl & Table & QueryParams & "&sysparm_offset=" & Text.From(Offset)
Second Approach:
Options = [
Headers=[Accept="application/json"],
领英推荐
Query = [
sysparm_fields = Text.From(Fields),
sysparm_query = Query,
sysparm_limit = Text.From(Limit),
sysparm_offset = Text.From(Offset),
sysparm_display_value = "true",
sysparm_exclude_reference_link = "true"
]
],
Source = Json.Document(Web.Contents(BaseUrl, Options)),
Data = try Source[result] otherwise null
in
Data,
2. Query Parameter Handling
First Approach:
Second Approach:
Conclusion
The second approach demonstrates a more reliable method for fetching data from APIs in Power BI, especially after publishing the dataset. By dynamically handling query parameters and constructing URLs within the Web.Contents function, you ensure compatibility and reduce the likelihood of errors. When working with Power BI and APIs, always use a method that dynamically manages query parameters for improved performance and reliability.
Let me know if you want the sample code or any questions on this. :)
Controller Planificación financiera en SPIN de Cruz Verde- Femsa División Salud
10 个月Cristian Rivera Torres
I help you create intuitive dashboards
10 个月Ruben Van de Voorde