cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
MarcoNeukom
Helper I
Helper I

Historical exchange rate API

Hi,

 

I am looking for a way to get historical exchange rates into my report - also daily updated rates - and I have been looking at ecb.europa.eu and their rest API, but find it difficult; 

does anyone know a fairly easy way to fetch these figures? 

Disclaimer; I have no developer skills - solely a business analyst, obviously... 

1 ACCEPTED SOLUTION

@MarcoNeukom I would suggest first creating a table with sequential dates on each row. Then by invoking the function, it will send the dates to the function one by one thus returning the exchange rate info for each day. You can use this example which first generates a list of dates of the past 365 days (this is updated with every refresh) and invokes the function:

 

let
    Source = {Number.From(Date.AddDays(DateTime.Date(DateTime.LocalNow()),-365))..Number.From(DateTime.Date(DateTime.LocalNow()))},
    #"Converted to Table" = Table.FromList(Source, Splitter.SplitByNothing(), null, null, ExtraValues.Error),
    #"Changed Type" = Table.TransformColumnTypes(#"Converted to Table",{{"Column1", type date}}),
    #"Renamed Columns" = Table.RenameColumns(#"Changed Type",{{"Column1", "Date"}}),
    #"Invoked Custom Function" = Table.AddColumn(#"Renamed Columns", "ExchangeRates", each Fn_GetHistoricExchangeRates(Date.ToText([Date],"yyyy-MM-dd"))),
    #"Expanded ExchangeRates" = Table.ExpandTableColumn(#"Invoked Custom Function", "ExchangeRates", {"Currency", "Rate"}, {"Currency", "Rate"}),
    #"Changed Type1" = Table.TransformColumnTypes(#"Expanded ExchangeRates",{{"Rate", type number}, {"Currency", type text}})
in
    #"Changed Type1"

In order for it to work you should create a function named Fn_GetHistoricExchangeRates, by using the code in my previous post.

 

Hope that helps!


Jan

View solution in original post

8 REPLIES 8
RBnNC
Helper I
Helper I

It can be done in ChristianSteven's PBRS

TeigeGao
Solution Sage
Solution Sage

Hi @MarcoNeukom ,

I will use data from this website: https://www.x-rates.com/historical/?from=USD&amount=1&date=2019-07-17, we can change the url to specified date to get historical exchange rates. Then we can use the web connector in PowerBI to get the data from them:
PBIDesktop_cEiyWMRHcJ.png

Best Regards,

Teige

So you update the URL everytime you want new data? 

Should be possible to get the latest data added to your previous queries and cached responses. 

Hi @TeigeGao,

 

Thx for your reply.

I should've been more specific:

 

What I am trying to achieve is to have a line chart with historical rates that refreshes with new datapoints every day. 

ECB has a syntax to do that, but I can't seem to get it to work.

https://sdw-wsrest.ecb.europa.eu/help/ 

 

@MarcoNeukom I have recently created a simple function that extracts exchange rate information from the site https://exchangeratesapi.io/ which gets its data from the ECB site:

let
    Source = (Date as text) => let
        Source = Json.Document(Web.Contents("https://api.exchangeratesapi.io/" & Date & "?base=USD")),
        rates = Source[rates],
        #"Converted to Table" = Record.ToTable(rates),
        #"Renamed Columns" = Table.RenameColumns(#"Converted to Table",{{"Name", "Currency"}, {"Value", "Rate"}})
    in
        #"Renamed Columns"
in
    Source

Using a datetable or generated range of dates, you can then invoke the custom function like this:

= Table.AddColumn(#"Removed Other Columns", "Rates", each Fn_GetHistoricCurrencyRates(DateTime.ToText([Date],"yyyy-MM-dd")))

Hope that helps!

 

Jan

@janvanwerkhoven this looks promising, I stumbled upon that site as well.

I am totally inexperienced with this; "invoke function" lets me enter parameter as date - should I fill in a range of dates and then use the second function you mention? 

@MarcoNeukom I would suggest first creating a table with sequential dates on each row. Then by invoking the function, it will send the dates to the function one by one thus returning the exchange rate info for each day. You can use this example which first generates a list of dates of the past 365 days (this is updated with every refresh) and invokes the function:

 

let
    Source = {Number.From(Date.AddDays(DateTime.Date(DateTime.LocalNow()),-365))..Number.From(DateTime.Date(DateTime.LocalNow()))},
    #"Converted to Table" = Table.FromList(Source, Splitter.SplitByNothing(), null, null, ExtraValues.Error),
    #"Changed Type" = Table.TransformColumnTypes(#"Converted to Table",{{"Column1", type date}}),
    #"Renamed Columns" = Table.RenameColumns(#"Changed Type",{{"Column1", "Date"}}),
    #"Invoked Custom Function" = Table.AddColumn(#"Renamed Columns", "ExchangeRates", each Fn_GetHistoricExchangeRates(Date.ToText([Date],"yyyy-MM-dd"))),
    #"Expanded ExchangeRates" = Table.ExpandTableColumn(#"Invoked Custom Function", "ExchangeRates", {"Currency", "Rate"}, {"Currency", "Rate"}),
    #"Changed Type1" = Table.TransformColumnTypes(#"Expanded ExchangeRates",{{"Rate", type number}, {"Currency", type text}})
in
    #"Changed Type1"

In order for it to work you should create a function named Fn_GetHistoricExchangeRates, by using the code in my previous post.

 

Hope that helps!


Jan

View solution in original post

Just note that this cannot be used in Power BI Service, it falls under a dynamic dataset and cannot be refreshed:

https://docs.microsoft.com/en-us/power-bi/connect-data/refresh-data#refresh-and-dynamic-data-sources

Helpful resources

Announcements
MBAS on Demand

2021 Release Wave 2 Plan

Power Platform release plan for the 2021 release wave 2 describes all new features releasing from October 2021 through March 2022.

July 2021 Update 768x460.png

Check it out!

Click here to read more about the July 2021 Updates

Power Query PA Forum 768x460.png

Check it out!

Did you know that you can visit the Power Query Forum in Power BI and now Power Apps

Urdu Hindi D365 Bootcamp 768x460.png

Urdu Hindi D365 Bootcamp

Dont miss our very own April Dunnam’s The Developer Guide to the Galaxy! Find out what the Power Platform has to offer for the traditional developer.