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

Join us at FabCon Atlanta from March 16 - 20, 2026, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM. Register now.

Reply
Alex_Yatlen
New Member

JSON API and function DO - WHILE

Hello everyone

Please help me to configure the correct function DO/WHILE in Power Query

 

I am trying to play a function from a video: https://www.youtube.com/watch?v=vhr4w5G8bRA

 

But the result of the function is an incorrectly limited list, referring to rest api (JSON) - the data is contained in 131 rows (one table have 100 rows by API limits=100), which corresponds to 2 tables, and the function creates more than 500 tables.

 
 

 

M code Generate Function:

 

= List.Generate( () =>
[Result = try GetData_Counter_Party(0) otherwise null, Page = 0],
each [Result] <> null,
each [Result = try GetData_Counter_Party([Page]+100) otherwise null, Page = [Page]+100],
each [Result])

 

GetData_Counter_Party function:

= (Number_offset as number) as table =>

let
Source = Json.Document(Web.Contents("https://online.*****/counterparty?limit=100&offset="&Number.ToText(Number_offset)&"")),
rows = Source[rows],
#"Converted to Table" = Table.FromList(rows, Splitter.SplitByNothing(), null, null, ExtraValues.Error)

in
#"Converted to Table"


Please help me to fix the code so that it does not create lines for empty api answers

3 REPLIES 3
Alex_Yatlen
New Member

Hello everyone

Please help me to configure the correct function DO/WHILE in Power Query

 

I am trying to play a function from a video: https://www.youtube.com/watch?v=vhr4w5G8bRA

 

But the result of the function is an incorrectly limited list, referring to rest api (JSON) - the data is contained in 131 rows (one table have 100 rows by API limits=100), which corresponds to 2 tables, and the function creates more than 500 tables.

a82ecc7c-8652-439b-a197-0c98222cbeb4.jpga82ecc7c-8652-439b-a197-0c98222cbeb24.jpg

 

M code Generate Function:

 

= List.Generate( () =>
[Result = try GetData_Counter_Party(0) otherwise null, Page = 0],
each [Result] <> null,
each [Result = try GetData_Counter_Party([Page]+100) otherwise null, Page = [Page]+100],
each [Result])

 

GetData_Counter_Party function:

= (Number_offset as number) as table =>

let
Source = Json.Document(Web.Contents("https://online.*****/counterparty?limit=100&offset="&Number.ToText(Number_offset)&"")),
rows = Source[rows],
#"Converted to Table" = Table.FromList(rows, Splitter.SplitByNothing(), null, null, ExtraValues.Error)

in
#"Converted to Table"


Please help me to fix the code so that it does not create lines for empty api answers

 

Hi @Alex_Yatlen ,

 

How about the result after you follow the suggestions mentioned in my original post?Could you please provide more details about it If it doesn't meet your requirement?


Best regards,

 

Community Support Team _ Dong Li
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
v-lid-msft
Community Support
Community Support

Hi @Alex_Yatlen ,

 

Could you please try to change the "each [Result] <> null"  to  the following:

 

each if [Result]  = null then false else if Table.RowCount([Result])=0 then false else true

 

If it does not work, could you please check the result of the GetData_Counter_Party function if the Number_offset  is 300 or 400?

 

Please don't have any Confidential Information or Real data in your reply.


Best regards,

 

Community Support Team _ Dong Li
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

Check out the October 2025 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Kudoed Authors