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

Earn the coveted Fabric Analytics Engineer certification. 100% off your exam for a limited time only!

Reply
hauffa
Frequent Visitor

Looping with List.Generate for API calls; Fails when only one loop needed

Happy Wednesday. I have the following code which calls a function that gets API results.  All works just fine as long as there's more than one loop needed (so > 500 records). I'd love to know what I'm doing wrong (and how I might write this better).  I've used this for several different APIs with success - this is the only one that is giving me issues. 

 

 

let
    Source = (wfReportId as text, optional aftCursor as text) => let Source =
            List.Generate(() =>
                [
                    Result = try fnGetComplianceFW(wfReportId, aftCursor) otherwise null
                    , afterCursor = Result[data][policyAssessments][pageInfo][endCursor]  
                ]
               
                , each [Result][data][policyAssessments][pageInfo][hasNextPage] <> false

                , each [
                    Result = try fnGetComplianceFW(wfReportId, [afterCursor]) otherwise null
                    , afterCursor  = Result[data][policyAssessments][pageInfo][endCursor]
                    ]

                , each [Result][data][policyAssessments][nodes]
               ),
        #"Converted to Table" = Table.FromList(Source, Splitter.SplitByNothing(), null, null, ExtraValues.Error)
    in
        #"Converted to Table"
in
    Source

 

 

Thanks in advance,

hauffa

 

1 ACCEPTED SOLUTION
lbendlin
Super User
Super User

rethink and change the exit condition

 

each [Result][data][policyAssessments][pageInfo][hasNextPage] <> false

View solution in original post

2 REPLIES 2
hauffa
Frequent Visitor

Thank you.  I ended up going with this. It seems to be working.

 

, each List.IsEmpty([Result][data][graphSearch][nodes]) = false

 

lbendlin
Super User
Super User

rethink and change the exit condition

 

each [Result][data][policyAssessments][pageInfo][hasNextPage] <> false

Helpful resources

Announcements
April AMA free

Microsoft Fabric AMA Livestream

Join us Tuesday, April 09, 9:00 – 10:00 AM PST for a live, expert-led Q&A session on all things Microsoft Fabric!

March Fabric Community Update

Fabric Community Update - March 2024

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

Top Solution Authors
Top Kudoed Authors