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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends September 15. Request your voucher.

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
August Power BI Update Carousel

Power BI Monthly Update - August 2025

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

August 2025 community update carousel

Fabric Community Update - August 2025

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

Top Kudoed Authors