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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Anonymous
Not applicable

Build a toggle/slicer for currency conversion

Hello Friends,

 

I have two tables. One is currency conversion_rate table and second is the fact table. They are both joined on Currency.

I want to build a slicer (or toggle) by which I can select the currency and the Price gets converted using the conversion rate from the other table.

Simple expected solution - I do not want a full all to all conversion. I only want X currency(any) Vs EUR toggle (in the example GBP and EUR). Every Price should be able to convert in to EUR by clicking somewhere (like on a toggle slicer)

 

Thanks.

 

Here are the tables

 

CurrencyCONVERSION_RATE
ARS73.25684257
BDT82.30264599
BGN1.827857452
CAD1.495088615
CHF0.953521944
CLP871.2290893
CNY6.850970883
COP3619.889557
CZK23.6299849
DKK6.450662402
EUR0.87831384
GBP0.733943605
HKD9.870237762
HUF343.4156459
INR83.06085896
MXN28.26554894
NOK14.76276735
PLN3.688233902
RON2.920294554
RSD83.95242482
SEK7.83124562
TWD31.78877778
USD1.052703153

 

ProductCurrencyPriceNew Measure
AGBP10 
BGBP15 
CGBP12 
DGBP14 
EGBP15 
FGBP10 
GGBP20 
HGBP12 
1 REPLY 1
Anonymous
Not applicable

// Keep XRates disconnected. Assuming that
// the table stores rates of conversion from
// the indicated currency to some other, but common,
// currency. In other words, the rate tells us
// the amount of the currency that you have to pay for
// 1 unit of the target currency (whatever it is,
// but for this calculation it does not matter in the
// slightest).
//
// Here's a measure that will display totals
// in any currency you want...

[Total] =
IF( HASONEFILTER( XRates[Currency] ),

	var __targetCurr = SELECTEDVALUE( XRates[Currency] )
	var __targetCurrXrate = SELECTEDVALUE( XRates[xrate] )
	return
	SUMX(
		// Iterating over currencies in the current
		// context to speed up the calculation. If
		// we iterate over products there'll be much
		// more computation. There are far fewer currencies
		// than products, right?
		VALUES( 'Product'[Currency] ),
		
		// get the currency of the
		// products we right now iterate over
		var __originalCurr = Product[Currency]
		// got the xrate for this currency
		var __originalCurrXrate =
			CALCULATE(
				SELECTEDVALUE( XRates[xrate] ),
				XRates[Currency] = __originalCurr,
				ALL( XRates )
			)
		// get the total price of the products
		// with the current currency
		var __total = CALCULATE( SUM( 'Product'[Price] ) )
		// express the total in the original xrate
		var __valueInCommonCurr = 
			__total * __originalCurrXrate
		// express the above total in the target currency
		var __valueInTargetCurr =
			__valueInCommonCurr / __targetCurrXrate
		return
			__valueInTargetCurr
	)
)

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

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