We've captured the moments from FabCon & SQLCon that everyone is talking about, and we are bringing them to the community, live and on-demand. Starts on April 14th. Register now
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
If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.
A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.
Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.
| User | Count |
|---|---|
| 57 | |
| 38 | |
| 33 | |
| 19 | |
| 16 |
| User | Count |
|---|---|
| 68 | |
| 66 | |
| 41 | |
| 34 | |
| 25 |