Forum Discussion

Centaur1's avatar
Centaur1
Regular Visitor
1 year ago
Solved

Lookup a Currency Rate according to a Date

Hello Experts   I have a append query with 3 columns.  the fields in the append query are Date, Rate, Curr (for Currency).   I have 4 different currencies:  USD, EUR, GBP, DKK What I need is to ...
  • rohit1991's avatar
    1 year ago

    hi Centaur1 ,

    Here's the concise Power Query M code to calculate USD Amount:

    let
    // Load queries
    Stampli = YourStampliTable,
    CurrencyRates = YourCurrencyRateTable,
    
    // Merge Stampli with CurrencyRates
    MergedTable = Table.NestedJoin(Stampli, {"WDDate", "Currency"}, CurrencyRates, {"Date", "Curr"}, "MergedRates", JoinKind.LeftOuter),
    
    // Expand the Rate column
    
    ExpandedTable = Table.ExpandTableColumn(MergedTable, "MergedRates", {"Rate"}),
    
    // Add USD Amount column
    AddUSDColumn = Table.AddColumn(ExpandedTable, "USD Amount", each if [Currency] = "USD" then [Amount] else [Amount] * [Rate], type number)
    in
    AddUSDColumn