The ultimate Fabric, Power BI, SQL, and AI community-led learning event. Save €200 with code FABCOMM.
Get registeredEnhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends September 15. Request your voucher.
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
Solved! Go to Solution.
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.
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.