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

Get certified in Microsoft Fabric—for free! For a limited time, get a free DP-600 exam voucher to use by the end of 2024. Register now

Reply
Rajiv1237
Resolver I
Resolver I

Dynamic Exchange Rate architecture and DAX calculation in Power BI

I want to get my amount to change as per currency code selected dynamically.

 

In my FactSales table I have currency and Amount. If user want to see that amount in any currency he select the currency from slicer and my excahnge rate will apply to that amount.

 

I tried below DAX to get dynamic Exchange Rate but no luck:

 

 

ExchangeRate = CALCULATE(MIN(ExchangeRate[ExcahngeRate]), FILTER(ExchangeRate, AND(AND(AND(MIN(FactSales[TransDate])>=MIN(ExchangeRate[ValidFrom]), MIN(FactSales[TransDate])<=IF(ISBLANK(MIN(ExchangeRate[ValidTo])), DATEVALUE("01-01-2070"), MIN(ExchangeRate[ValidTo]))), MIN(ExchangeRate[FromCurrencyCode]) = MIN(FactSales[CurrencyCode])), MIN(ExchangeRate[ToCurrencyCode]) = FIRSTNONBLANK(ExchangeRate[ToCurrencyCode],1))))

 

ExchangeRate = CALCULATE(MIN(ExchangeRate[ExcahngeRate]), FILTER(ExchangeRate, AND(AND(AND(MIN(FactSales[TransDate])>=MIN(ExchangeRate[ValidFrom]), MIN(FactSales[TransDate])<=IF(ISBLANK(MIN(ExchangeRate[ValidTo])), DATEVALUE("01-01-2070"), MIN(ExchangeRate[ValidTo]))), MIN(ExchangeRate[FromCurrencyCode]) = MIN(FactSales[CurrencyCode])), MIN(ExchangeRate[ToCurrencyCode]) = FIRSTNONBLANK(ExchangeRate[ToCurrencyCode],1))))

 

https://drive.google.com/file/d/1BCD3cycq-tNTc9xPEK458dn-BjJj9Qao/view?usp=sharing

 

DynamicExchangeRate_1.PNGDynamicExchangeRate_2.PNG 

1 ACCEPTED SOLUTION
Rajiv1237
Resolver I
Resolver I

If we have Exchange rate on daily basis then we can go for below solution:

https://www.kasperonbi.com/currency-conversion-in-dax-for-power-bi-and-ssas/DynamicExchangeRate_3.PNG

 

 

 

 

 

 

If we have Exchange Rate as date range then use dynamic DAX:

ExchangeRate = 
IF(ISBLANK
	(
		CALCULATE(MIN(ExchangeRate[ExcahngeRate]), 
		FILTER(FILTER(ExchangeRate, AND(AND(ExchangeRate[FromCurrencyCode] = MIN(FactSales[TransactionCurrencyCode]), ExchangeRate[ToCurrencyCode] = FIRSTNONBLANK(ExchangeRate[ToCurrencyCode],1))
		, MIN(FactSales[TransDate])<=IF(ISBLANK(ExchangeRate[ValidTo].[Date]), DATEVALUE("2070-01-01"), ExchangeRate[ValidTo]))), MIN(FactSales[TransDate])>= ExchangeRate[ValidFrom]))
	)
	, 1
	, CALCULATE(MIN(ExchangeRate[ExcahngeRate]), 
		FILTER(FILTER(ExchangeRate, AND(AND(ExchangeRate[FromCurrencyCode] = MIN(FactSales[TransactionCurrencyCode])
		, ExchangeRate[ToCurrencyCode] = FIRSTNONBLANK(ExchangeRate[ToCurrencyCode],1))
		, MIN(FactSales[TransDate])<=IF(ISBLANK(ExchangeRate[ValidTo].[Date]), DATEVALUE("2070-01-01"), ExchangeRate[ValidTo])))
		, MIN(FactSales[TransDate])>= ExchangeRate[ValidFrom]))
)

DynamicExchangeRate_1.PNG

 

DynamicExchangeRate_2.PNG

 

 

 

View solution in original post

1 REPLY 1
Rajiv1237
Resolver I
Resolver I

If we have Exchange rate on daily basis then we can go for below solution:

https://www.kasperonbi.com/currency-conversion-in-dax-for-power-bi-and-ssas/DynamicExchangeRate_3.PNG

 

 

 

 

 

 

If we have Exchange Rate as date range then use dynamic DAX:

ExchangeRate = 
IF(ISBLANK
	(
		CALCULATE(MIN(ExchangeRate[ExcahngeRate]), 
		FILTER(FILTER(ExchangeRate, AND(AND(ExchangeRate[FromCurrencyCode] = MIN(FactSales[TransactionCurrencyCode]), ExchangeRate[ToCurrencyCode] = FIRSTNONBLANK(ExchangeRate[ToCurrencyCode],1))
		, MIN(FactSales[TransDate])<=IF(ISBLANK(ExchangeRate[ValidTo].[Date]), DATEVALUE("2070-01-01"), ExchangeRate[ValidTo]))), MIN(FactSales[TransDate])>= ExchangeRate[ValidFrom]))
	)
	, 1
	, CALCULATE(MIN(ExchangeRate[ExcahngeRate]), 
		FILTER(FILTER(ExchangeRate, AND(AND(ExchangeRate[FromCurrencyCode] = MIN(FactSales[TransactionCurrencyCode])
		, ExchangeRate[ToCurrencyCode] = FIRSTNONBLANK(ExchangeRate[ToCurrencyCode],1))
		, MIN(FactSales[TransDate])<=IF(ISBLANK(ExchangeRate[ValidTo].[Date]), DATEVALUE("2070-01-01"), ExchangeRate[ValidTo])))
		, MIN(FactSales[TransDate])>= ExchangeRate[ValidFrom]))
)

DynamicExchangeRate_1.PNG

 

DynamicExchangeRate_2.PNG

 

 

 

Helpful resources

Announcements
November Carousel

Fabric Community Update - November 2024

Find out what's new and trending in the Fabric Community.

Live Sessions with Fabric DB

Be one of the first to start using Fabric Databases

Starting December 3, join live sessions with database experts and the Fabric product team to learn just how easy it is to get started.

Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Early Bird pricing ends December 9th.

Nov PBI Update Carousel

Power BI Monthly Update - November 2024

Check out the November 2024 Power BI update to learn about new features.