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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
WillY_OneEyed
New Member

Use a list of countries

Hi guys,

I need to bring all "GDP (current US$)" indicator of all countries using powerquery:

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-jianboli-msft
Community Support
Community Support

Hi @WillY_OneEyed ,

 

You can modify your Power Query code to loop through a list of countries and fetch the "GDP (current US$)" indicator for each country. First, you need to create a list of country codes. Then, you can use

List.Accumulate to iterate through the list of countries and fetch the data for each country. Here's an example of how you can modify your code:

let
    CountryList = {"USA", "GBR", "FRA", "DEU"}, // Replace this with your list of country codes
    Source = List.Accumulate(
        CountryList,
        {},
        (s, countryCode) => s & List.Accumulate(
            {1..10},
            {},
            (s2, c) => s2 & Json.Document(Web.Contents("https://api.worldbank.org/v2/country/" & countryCode & "/indicator/NY.GDP.MKTP.CD/?format=json&page=" & Number.ToText(c))){1}
        )
    ),
    #"Table From Records" = Table.FromRecords(Source)
in
    #"Table From Records"

Replace CountryList with your list of country codes, and the modified code will fetch the "GDP (current US$)" indicator for each country in the list.

Besides, here is a detailed document about how to use world bank api:

API Document (worldbank.org)

Hope it would help you.

 

Best Regards,

Jianbo Li

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-jianboli-msft
Community Support
Community Support

Hi @WillY_OneEyed ,

 

You can modify your Power Query code to loop through a list of countries and fetch the "GDP (current US$)" indicator for each country. First, you need to create a list of country codes. Then, you can use

List.Accumulate to iterate through the list of countries and fetch the data for each country. Here's an example of how you can modify your code:

let
    CountryList = {"USA", "GBR", "FRA", "DEU"}, // Replace this with your list of country codes
    Source = List.Accumulate(
        CountryList,
        {},
        (s, countryCode) => s & List.Accumulate(
            {1..10},
            {},
            (s2, c) => s2 & Json.Document(Web.Contents("https://api.worldbank.org/v2/country/" & countryCode & "/indicator/NY.GDP.MKTP.CD/?format=json&page=" & Number.ToText(c))){1}
        )
    ),
    #"Table From Records" = Table.FromRecords(Source)
in
    #"Table From Records"

Replace CountryList with your list of country codes, and the modified code will fetch the "GDP (current US$)" indicator for each country in the list.

Besides, here is a detailed document about how to use world bank api:

API Document (worldbank.org)

Hope it would help you.

 

Best Regards,

Jianbo 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
LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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