Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
7 years ago
Solved

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 ...
  • Anonymous's avatar
    Anonymous
    7 years ago

    Anonymous 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