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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
nnouchi
Helper I
Helper I

Extracting Data from API and transform into tables

Greetings Power BI community,

 

I am having trouble understanding the steps necessary to extract and format data from an API source to be used practically in Power BI. 

data source.PNG

This is the outcome of my dataset when I load the api through the Power Query editor. The first thing I'd like to know is how to extract the list of columns and match those columns to the data source. When I expand on the list for "data", I get directed to another table that is comprised of all of the data values in a multi-row format:Data - API.PNG

 

 

Going one more level deeper, I have an outcome of of one column with a bunch of row values that should be tied as one row record instead of the 13 rows I have in this upcoming image:

Api 2.PNG

 

Now is it possible to transform the data set to include all column headers with each specific data point?

 

I have been able to create reports using APIs through Python but I want the ability to refresh this data source on a weekly basis and have reactive visualizations.

 

I apologize for the length of this question and my knowledge of M is very limited therefore any help would be greatly appreciated.

 

This is the source I'm attempting to query:

 

https://www.quandl.com/api/v3/datasets/LME/PR_NI.json?api_key=**************

 

 

Thanks,

 

Nicolas Nouchi

 

 

1 ACCEPTED SOLUTION
ImkeF
Super User
Super User

Hi @nnouchi,

there is a very easy way to retrieve the TS-data from Quandl:

 

let
    Source = Json.Document(Web.Contents("https://www.quandl.com/api/v3/datasets/LME/PR_NI.json?api_key=xxxxxxxx")),
    dataset = Source[dataset],
    ExpandAllQuandl = Table.FromRows(dataset[data], dataset[column_names])
in
    ExpandAllQuandl

Works with all sources and will definitely refresh in the service as well.

Imke Feldmann (The BIccountant)

If you liked my solution, please give it a thumbs up. And if I did answer your question, please mark this post as a solution. Thanks!

How to integrate M-code into your solution -- How to get your questions answered quickly -- How to provide sample data -- Check out more PBI- learning resources here -- Performance Tipps for M-queries

View solution in original post

6 REPLIES 6
ImkeF
Super User
Super User

Hi @nnouchi,

there is a very easy way to retrieve the TS-data from Quandl:

 

let
    Source = Json.Document(Web.Contents("https://www.quandl.com/api/v3/datasets/LME/PR_NI.json?api_key=xxxxxxxx")),
    dataset = Source[dataset],
    ExpandAllQuandl = Table.FromRows(dataset[data], dataset[column_names])
in
    ExpandAllQuandl

Works with all sources and will definitely refresh in the service as well.

Imke Feldmann (The BIccountant)

If you liked my solution, please give it a thumbs up. And if I did answer your question, please mark this post as a solution. Thanks!

How to integrate M-code into your solution -- How to get your questions answered quickly -- How to provide sample data -- Check out more PBI- learning resources here -- Performance Tipps for M-queries

@ImkeF Thank you very much, that was easier than I expected.

 

 

Hi @nnouchi @ImkeF could you please help me understand where the solution script should be written? I am trying to achieve a similar result with an API data source. Thank you so much.

Hi again 🙂 I have adjusted the code you shared to include the API URL I am working with within the query editor. My apologies for the very novice questions, but I am not sure how to troubleshoot the error I'm recieving "The field 'dataset' of the record wasn't found." Thank you so much for any guidance! 

 

let
    Source = Json.Document(Web.Contents("https://clinicaltrials.gov/api/query/study_fields?&max_rnk=1000&fmt=json&fields=BriefTitle,InterventionName,InterventionType,LastKnownStatus,LeadSponsorName")),
    dataset = Source[dataset],
    ExpandAll = Table.FromRows(dataset[data], dataset[column_names])
in
    ExpandAll

 

nnouchi
Helper I
Helper I

Okay, I have figured out how to extract the dataset of values and just renamed the columns as they would be in the column headers, however, I don't think this would work with any updated refresh since the data had to be manipulated and transformed.

 

 

Hi @nnouchi,

 

I'm glad you made it. You can refresh it if you did all the manipulations and transformations in the Query Editor. Please refer to the snapshot below. The steps record all your operations. They will be applied to the new data. Please give it a try.

Extracting-Data-from-API-and-transform-into-tables

 

 

Best Regards,
Dale

Community Support Team _ Dale
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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