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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
WillY_OneEyed
New Member

A list of lists

Hi All.

 

In the other opportunity, @ThxAlot helped me with a solution. Now, I need to complement the other solution.

The other problem was solved with the following code:

let
    Source = List.Accumulate(
        {1..100},
        {},
        (s,c) => s & Json.Document(Web.Contents("http://api.worldbank.org/v2/country?format=json&page=" & Number.ToText(c))){1}
    ),
    #"Table From Records" = Table.FromRecords(Source)
in
    #"Table From Records"

 

Now I need to bring all "GDP (current US$)" indicator of all countries. Using the past solution I have:

let
    Source = List.Accumulate(
        {1..10},
        {},
        (s,c) => s & Json.Document(Web.Contents("https://api.worldbank.org/v2/country/USA/indicator/NY.GDP.MKTP.CD/?format=json&page=" & Number.ToText(c))){1}
    ),
    #"Table From Records" = Table.FromRecords(Source)
in
    #"Table From Records"

 

Here's the problem. I need change "USA" for a list of countries.

 

Ty folks

 

1 ACCEPTED SOLUTION
v-yanjiang-msft
Community Support
Community Support

Hi @WillY_OneEyed ,

To modify the code to include a list of countries instead of just "USA", you can replace the hardcoded "USA" with a parameter that takes a list of countries. Here's an updated version of the code:

let
    GetGDP = (country as text) =>
        let
            Source = List.Accumulate(
                {1..10},
                {},
                (s,c) => s & Json.Document(Web.Contents("https://api.worldbank.org/v2/country/" & country & "/indicator/NY.GDP.MKTP.CD/?format=json&page=" & Number.ToText(c))){1}
            ),
            #"Table From Records for  & country" = Table.FromRecords(Source)
        in
            #"Table From Records for  & country",
    Countries = {"USA", "CAN", "MEX"}, // Replace with your list of countries
    GDPTables = List.Transform(Countries, each GetGDP(_)),
    CombinedTable = Table.Combine(GDPTables)
in
    CombinedTable

This code defines a function called "GetGDP" that takes a country as a parameter and returns a table of GDP data for that country. It then applies this function to each country in the list using the List.Transform function, and combines the resulting tables into a single table using Table.Combine.

 

Best regards,

Community Support Team_yanjiang

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

1 REPLY 1
v-yanjiang-msft
Community Support
Community Support

Hi @WillY_OneEyed ,

To modify the code to include a list of countries instead of just "USA", you can replace the hardcoded "USA" with a parameter that takes a list of countries. Here's an updated version of the code:

let
    GetGDP = (country as text) =>
        let
            Source = List.Accumulate(
                {1..10},
                {},
                (s,c) => s & Json.Document(Web.Contents("https://api.worldbank.org/v2/country/" & country & "/indicator/NY.GDP.MKTP.CD/?format=json&page=" & Number.ToText(c))){1}
            ),
            #"Table From Records for  & country" = Table.FromRecords(Source)
        in
            #"Table From Records for  & country",
    Countries = {"USA", "CAN", "MEX"}, // Replace with your list of countries
    GDPTables = List.Transform(Countries, each GetGDP(_)),
    CombinedTable = Table.Combine(GDPTables)
in
    CombinedTable

This code defines a function called "GetGDP" that takes a country as a parameter and returns a table of GDP data for that country. It then applies this function to each country in the list using the List.Transform function, and combines the resulting tables into a single table using Table.Combine.

 

Best regards,

Community Support Team_yanjiang

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

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

Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

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.