This is best Fabric, Power BI, SQL and AI community event. How do we know? The last event sold out! Save €200 with code FABCMTY200.
Register nowA new Data Days event is coming soon! This time we’re going bigger than ever. Fabric, Power BI, SQL, AI and more. Don't miss out.
Currently I am using the following code to loop through pages until an empty page is reached by using Table.RowCount([Func]) >= 1.
Now I wanna change the code such that the looping stops when the records reached certain "CreatedDate" to retrieve only the most updated pages of records. I am so stuck in setting up the looping condition as nothing seems working, any idea? many thanks!
let
GetAllData = (Project as any) => let
GetData = (Page as number) =>
let
Source = Json.Document(Web.Contents(CompanyURL , [RelativePath = "/" & Project & "/api/v2/formitems?key=" & APIKey & "&pagesize=5000&page=" & Number.ToText(Page)])),
#"Converted to Table" = Table.FromList(Source, Splitter.SplitByNothing(), null, null, ExtraValues.Error)
in
#"Converted to Table",
#"List" =
List.Generate( ()=>
[Page=0, Func=null],
each [Page] = 0 or Table.RowCount([Func]) >= 1,
each [Page =_[Page]+1,
Func=GetData([Page]+1)],
each _[Func]),
#"Converted to Table" = Table.FromList(List, Splitter.SplitByNothing(), null, null, ExtraValues.Error),
#"Removed Top Rows" = Table.Skip(#"Converted to Table",1),
#"Expanded Column1" = Table.ExpandTableColumn(#"Removed Top Rows", "Column1", {"Column1"}, {"Column1.1"}),
#"Expanded Column1.1" = Table.ExpandRecordColumn(#"Expanded Column1", "Column1.1", {"ID", "CreatedDate"}, {"ID", "CreatedDate"}),
in
#"Expanded Column1.1",
Project = () =>
let
Source = Json.Document(Web.Contents(CompanyURL, [RelativePath = "/Admin/api/projects?key=" & APIKey])),
#"Converted to Table" = Table.FromList(Source, Splitter.SplitByNothing(), null, null, ExtraValues.Error),
#"Expanded Column1" = Table.ExpandRecordColumn(#"Converted to Table", "Column1", {"URL", "Finished"}, {"URL", "Finished"}),
#"Filtered Rows" = Table.SelectRows(#"Expanded Column1", each ([Finished] = false)),
#"Inserted Text After Delimiter" = Table.AddColumn(#"Filtered Rows", "Text After Delimiter", each Text.AfterDelimiter([URL], "/"), type text),
#"Renamed Columns" = Table.RenameColumns(#"Inserted Text After Delimiter",{{"Text After Delimiter", "Project"}, {"URL", "FullURL"}}),
#"Removed Columns" = Table.RemoveColumns(#"Renamed Columns",{"Finished"})
in
#"Removed Columns",
Source = Project (),
#"Added Custom" = Table.AddColumn(Source, "Custom", each GetAllData([Project])),
in
#"Added Custom"
Hi @nuance ,
how would you know the most updated data before entering the loop?
Or: If you need to determine that while looping: Wouldn't you have to run through the whole loop until finding out the most recent one?
So: Please share the logic how the most recent date can be determined.
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
Check out the May 2026 Power BI update to learn about new features.
Sign up to receive a private message when registration opens and key events begin.
If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.
| User | Count |
|---|---|
| 31 | |
| 26 | |
| 23 | |
| 22 | |
| 15 |
| User | Count |
|---|---|
| 63 | |
| 45 | |
| 28 | |
| 24 | |
| 22 |