Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

Reply
IvanS
Helper V
Helper V

Exchange rate for specific date range based on posting date

Dear all,

 

could you please help me with writing following DAX formula as calculated column "Exchange rate" in my FACT_Invoices table.

 

I have table DIM_ExchangeRates that contains rates that are updated with irregular frequency - only in case of significant rate change. As the table consists of duplicates, there is no relationship to to the FACT_Invoices table.

 

CurrencyExchange RateValid From
PLN4.31.1.2020
USD1.21.3.2020
PLN4.51.6.2021
USD1.11.1.2022
PLN4.61.1.2022

 

Sample of FACT_Invoices tables is following. I am trying to get the exchange rate valid for the specific currency and valid within the given date range from DIM_ExchangeRates table. If the currency is EUR, then set the exchange rate to 1, as the next step will be to create simple DIVIDE function Amount in EUR = Amount/Exchange rate.

 

Invoice No.AmountPosting DateCurrencyExchange rateAmount in EUR
1100015.3.2021EUR1 
25000031.5.2021PLN4.3 
350024.5.2020EUR1 
430001.11.2021USD1.2 
59000030.12.2021PLN4.5 

 

Thank you for any help!

Ivan

2 ACCEPTED SOLUTIONS
DataInsights
Super User
Super User

@IvanS,

 

Try this calculated column in FACT_Invoices:

 

Exchange rate = 
VAR vPostingDate = FACT_Invoices[Posting Date]
VAR vCurrency = FACT_Invoices[Currency]
VAR vMaxValidFrom =
    CALCULATE (
        MAX ( DIM_ExchangeRates[Valid From] ),
        DIM_ExchangeRates[Currency] = vCurrency,
        DIM_ExchangeRates[Valid From] < vPostingDate
    )
VAR vRate =
    CALCULATE (
        MAX ( DIM_ExchangeRates[Exchange Rate] ),
        DIM_ExchangeRates[Currency] = vCurrency,
        DIM_ExchangeRates[Valid From] = vMaxValidFrom
    )
VAR vResult =
    IF ( vCurrency = "EUR", 1, vRate )
RETURN
    vResult

 

DataInsights_0-1651672137206.png

 





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




View solution in original post

@IvanS,

 

Glad to hear that worked. Thanks for letting me know--I've updated the DAX:

 

Exchange rate = 
VAR vPostingDate = FACT_Invoices[Posting Date]
VAR vCurrency = FACT_Invoices[Currency]
VAR vMaxValidFrom =
    CALCULATE (
        MAX ( DIM_ExchangeRates[Valid From] ),
        DIM_ExchangeRates[Currency] = vCurrency,
        DIM_ExchangeRates[Valid From] <= vPostingDate
    )
VAR vRate =
    CALCULATE (
        MAX ( DIM_ExchangeRates[Exchange Rate] ),
        DIM_ExchangeRates[Currency] = vCurrency,
        DIM_ExchangeRates[Valid From] = vMaxValidFrom
    )
VAR vResult =
    IF ( vCurrency = "EUR", 1, vRate )
RETURN
    vResult




Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




View solution in original post

3 REPLIES 3
DataInsights
Super User
Super User

@IvanS,

 

Try this calculated column in FACT_Invoices:

 

Exchange rate = 
VAR vPostingDate = FACT_Invoices[Posting Date]
VAR vCurrency = FACT_Invoices[Currency]
VAR vMaxValidFrom =
    CALCULATE (
        MAX ( DIM_ExchangeRates[Valid From] ),
        DIM_ExchangeRates[Currency] = vCurrency,
        DIM_ExchangeRates[Valid From] < vPostingDate
    )
VAR vRate =
    CALCULATE (
        MAX ( DIM_ExchangeRates[Exchange Rate] ),
        DIM_ExchangeRates[Currency] = vCurrency,
        DIM_ExchangeRates[Valid From] = vMaxValidFrom
    )
VAR vResult =
    IF ( vCurrency = "EUR", 1, vRate )
RETURN
    vResult

 

DataInsights_0-1651672137206.png

 





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




Thank you very much! Very helpful solution! Just one small adjustment in the code - can you please change that in your post for other users?

 

DIM_ExchangeRates[Valid From] <= vPostingDate

 

@IvanS,

 

Glad to hear that worked. Thanks for letting me know--I've updated the DAX:

 

Exchange rate = 
VAR vPostingDate = FACT_Invoices[Posting Date]
VAR vCurrency = FACT_Invoices[Currency]
VAR vMaxValidFrom =
    CALCULATE (
        MAX ( DIM_ExchangeRates[Valid From] ),
        DIM_ExchangeRates[Currency] = vCurrency,
        DIM_ExchangeRates[Valid From] <= vPostingDate
    )
VAR vRate =
    CALCULATE (
        MAX ( DIM_ExchangeRates[Exchange Rate] ),
        DIM_ExchangeRates[Currency] = vCurrency,
        DIM_ExchangeRates[Valid From] = vMaxValidFrom
    )
VAR vResult =
    IF ( vCurrency = "EUR", 1, vRate )
RETURN
    vResult




Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




Helpful resources

Announcements
Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

Check out the October 2025 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors