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

The Power BI DataViz World Championships are on! With four chances to enter, you could win a spot in the LIVE Grand Finale in Las Vegas. Show off your skills.

Reply
LarryBroward
Helper I
Helper I

API Loop not working in M Query

Hi,

 

In the code below I can see the day increment is working the first time thru but it doesn't increment and call the api a second time.

Is there anything obvious that I am doing wrong.

Thanks 

 

 

(ApiParamStartDate as date,ApiParamEndDate as date,optional loop as number,optional data as list) =>

let

newstart = Date.AddDays(ApiParamStartDate,1),

sd = Date.ToText(newstart) & "%2000%3A00",
ed = Date.ToText(newstart) & "%2023%3A59",

Source =

// call a 61 second delay function here
//Function.InvokeAfter(

 

Json.Document(Web.Contents(
"https://cloud.com/api/v4/get_readings/?device_sn=12345&start_date=" &Text.From(sd)&"&end_date="&Text.From(ed)&"&output_format=json&page_num=1&per_page=2000",
[Headers=[Accept="application/json", Authorization="Token xxxxx"]])),

 

//#duration(0,0,1,1))),

 

//loop
loopNum = loop + 1,

currentData = Record.ToList(Source[data]) ,

appendedData =

if currentData is null and data is null then {}
else if data is null then List.Combine({{}, currentData})
else if data is null then List.Combine ({data,{}})
else List.Combine(data,currentData) ,

 

output =

if ApiParamStartDate <= ApiParamEndDate or loopNum < 10
then
appendedData

else
@#"GET Activity" (ApiParamStartDate,ApiParamEndDate,loopNum, appendedData)

in output

 

 

 

0 REPLIES 0

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!

Feb2025 Sticker Challenge

Join our Community Sticker Challenge 2025

If you love stickers, then you will definitely want to check out our Community Sticker Challenge!

Feb2025 NL Carousel

Fabric Community Update - February 2025

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

Top Solution Authors
Top Kudoed Authors