Forum Discussion
Anonymous
6 years agoNot applicable
Convert Measure to calculation group
Hi all, I´ve this measures that convert sales currency (multiple currencies) to USD, EUR and GBP currency selected in a report slicer: CreationForex = IF ( ISFILTERED ( CreationForex[Currency...
Anonymous
6 years agoNot applicable
I think this code is more efficient:
CreationForex =
// You should calculate things
// only one time for the sake of speed.
VAR Measure_ = SELECTEDMEASURE() // [SumNetSalePrice]
RETURN
IF( HASONEFILTER( CreationForex[CurrencyTo] ),
VAR SaleCurrency =
SELECTEDVALUE( Sales[SaleCurrency] )
VAR ForexRate =
CALCULATE(
SELECTEDVALUE( CreationForex[Rate] ),
CreationForex[Currency] = SaleCurrency
)
VAR CurrencyFormat =
SELECTEDVALUE( CreationForex[CurrencyCharacter] )
VAR Result =
CONCATENATE(
CurrencyFormat,
FORMAT(
DIVIDE(
Measure_,
ForexRate,
0
),
"0.00"
)
)
RETURN
Result,
Measure_
)I'm not sure if calc groups work exactly the same in Power BI as the do in SSAS but the item above returns 2 different data types: string and a number. This is suboptimal, to say the least. This item should always return a number. I know that in Tabular Editor you can define the format string dynamically without affecting the value of the calculation. Please use this feature to set formatting correctly and remove formatting from the item.