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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
Anonymous
Not applicable

How do I Loop in M to Query Last 40 Days a Day at a Time Using Web URL API

Hi all,

So as fairly new to using M and Power Query, I was trying to adapt things from this post:
https://community.powerbi.com/t5/Desktop/Iterating-over-start-and-end-dates-for-multiple-API-calls/m...

 

I haven't got very far! Basically what I want to achieve is to create one table with the previous 40 days worth of data rather than last 12 months as the post above is tailored for. I currently pull this data using a web URL API, but in the API you can only call 1 day at a time. So I would need to create some kind of loop that advances the date that is specified in the API string by one, up to 40 times and have this reside in this one table.

 

How do I achieve that?

1 ACCEPTED SOLUTION
ImkeF
Super User
Super User

Hi @Anonymous ,
the simplest loop in Power Query is to add a column to a table: The command for the column will be applied for each row.
So you can create a table with the last 40 days in one column and then you add a custom column that makes the web call. There you reference the day-column to make a reference to each day.
But if you want to refresh that in the Power BI Service, you have to move parts of your URL to query parameters unfortunately: 

http://blog.datainspirations.com/2018/02/17/dynamic-web-contents-and-power-bi-refresh-errors/

 

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

2 REPLIES 2
ImkeF
Super User
Super User

Hi @Anonymous ,
the simplest loop in Power Query is to add a column to a table: The command for the column will be applied for each row.
So you can create a table with the last 40 days in one column and then you add a custom column that makes the web call. There you reference the day-column to make a reference to each day.
But if you want to refresh that in the Power BI Service, you have to move parts of your URL to query parameters unfortunately: 

http://blog.datainspirations.com/2018/02/17/dynamic-web-contents-and-power-bi-refresh-errors/

 

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

Greg_Deckler
Super User
Super User

@Anonymous Perhaps @edhans or @ImkeF can assist.



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
Power BI Cookbook Third Edition (Color)

DAX is easy, CALCULATE makes DAX hard...

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.

Top Solution Authors