Forum Discussion

Centaur1's avatar
Centaur1
Regular Visitor
1 year ago
Solved

Exchange Rates - Historical

Hello,   Can power query download historical FX rates but always to the current date? I have read some posts but it seems there is always a date range that is needin got be selected but the date ra...
  • rohit1991's avatar
    1 year ago

    Hi Centaur1 
    Yes, Power Query can fetch historical FX rates up to the current date dynamically:

    1. Use an API: Find a service like Open Exchange Rates  or CurrencyLayer  that supports historical rates.

    2. Dynamic Query: Use DateTime.LocalNow() in Power Query to set the end date dynamically. Example URL for Open Exchange Rates.

    3. Parse Data: Expand the response (JSON/XML) into a tabular format.

    4. Refresh Weekly: Set a weekly refresh under Query Properties.

    Example script:

    let
    StartDate = "2014-01-01",
    EndDate = Text.From(DateTime.LocalNow()),
    Source = Json.Document(Web.Contents("https://openexchangerates.org/api/time-series.json ", [
    Query = [app_id = "YOUR_API_KEY", base = "USD", start = StartDate, end = EndDate]
    ])),
    Rates = Table.FromRecords(Source[rates])
    in
    Rates