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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
dusdau
Helper II
Helper II

Looping thru a table to perform a REST API call with paging

Hi All,

 

I've been working on this one a while, and have found many good posts and videos to help but I can't quite get this to the finish line so hoping you can help.

 

I have a query called 'PhishingTests' as follows:

 

pst_idtotal_pages
1215
1238
1346
1413

 

pst_id represents the test id I need to get results for, and total_pages is the number of pages I need to get.  I have created a function to do this as follows:

 

dusdau_0-1597686765943.png

 

The function works...the part I can't figure out is exactly how to use the 'PhishingTests' query to provide the parameters to loop thru the function to get all the results.

 

I have tried adding column and invoking custom function from 'PhishingTests' but I get an ugly error.

 

dusdau_1-1597686957881.png

 

I assume this is due to the recursive nature of the function colliding with invoking it from the query.

 

I have also tried calling it from another query, like so:

 

let
testID = PhishingTests[pst_id],

totalPages = PhishingTests[total_pages],
results = List.Transform(testID, each fnGetTestResults(_, totalPages, 1))
in
results

 

However I am unable to get this to also pass thru the relative total_pages value for the function.  It errors since I think its trying to pass a list, erroring with "Expression.Error: We cannot convert a value of type List to type Number."

 

Any ideas how to structure this to make this work would be gratefully received! 

 

Thanks,

Dustin 

2 ACCEPTED SOLUTIONS
lbendlin
Super User
Super User

General approach is to use Table.AddColumn on your PhishingTests table where you call the fnGetTestResults and get the contents back into the new table cell (as a table in a table). Then you can decide if you just want to combine the values in that column, or do other fancy stuff with it.

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjQyVNJRMlWK1QGxjYFsCwjb2ATINoOwTUBqjJViYwE=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [pst_id = _t, total_pages = _t]),
    #"Added Custom" = Table.AddColumn(Source, "Content", each fnGetTestResults([pst_id],[total_pages],1))
in
    #"Added Custom"

 

Are you sure your API calls return JSON pages that an be converted into tables without issue?

View solution in original post

Thanks lbendlin! What you gave me is what I needed to focus on.  Here is what I finally got working:

 

Add Column -> Invoke Custom Function

dusdau_0-1597711274173.png

 

Function 1

dusdau_1-1597711337629.png

 

Function 2

dusdau_2-1597711411525.png

 

Seems to work great!  Thanks again!  Hope this helps someone else...

View solution in original post

3 REPLIES 3
lbendlin
Super User
Super User

General approach is to use Table.AddColumn on your PhishingTests table where you call the fnGetTestResults and get the contents back into the new table cell (as a table in a table). Then you can decide if you just want to combine the values in that column, or do other fancy stuff with it.

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjQyVNJRMlWK1QGxjYFsCwjb2ATINoOwTUBqjJViYwE=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [pst_id = _t, total_pages = _t]),
    #"Added Custom" = Table.AddColumn(Source, "Content", each fnGetTestResults([pst_id],[total_pages],1))
in
    #"Added Custom"

 

Are you sure your API calls return JSON pages that an be converted into tables without issue?

Thanks lbendlin! What you gave me is what I needed to focus on.  Here is what I finally got working:

 

Add Column -> Invoke Custom Function

dusdau_0-1597711274173.png

 

Function 1

dusdau_1-1597711337629.png

 

Function 2

dusdau_2-1597711411525.png

 

Seems to work great!  Thanks again!  Hope this helps someone else...

By the way, 

 

List.Combine({results,{testResults}})

 

is a bit rich. You should be able to write:

 

results & testResults

 

to get the same output.

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 community update carousel

Fabric Community Update - June 2025

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