Forum Discussion
Anonymous
4 years agoNot applicable
Alternative LookupValue function to create virtual relationship.
Developing my first power bi data model. Below tables are part of my data model. FxRatePeriod Currency Rate Jan-22 Euro 1.05 Jan-22 GBP 1.2 Feb-22 Euro ...
- 4 years ago
Anonymous,
This solution uses a Currency table that functions as a bridge table between the ExchangeRate and Transaction tables. The Currency table can be created in DAX or Power Query. The column ExchangeRate[FxRatePeriod] uses the first day of the month.
Measures:
ConvertedAmount = SUMX ( 'Transaction', VAR vRate = MAXX ( RELATEDTABLE ( ExchangeRate ), ExchangeRate[Rate] ) RETURN 'Transaction'[OrigAmount] * vRate )PrevMonthRateConvertedAmount = SUMX ( 'Transaction', VAR vCurrency = 'Transaction'[Currency] VAR vPeriod = EDATE ( SELECTEDVALUE ( ExchangeRate[FxRatePeriod] ), -1 ) VAR vTable = FILTER ( ALL ( ExchangeRate ), ExchangeRate[Currency] = vCurrency && ExchangeRate[FxRatePeriod] = vPeriod ) VAR vRate = MAXX ( vTable, ExchangeRate[Rate] ) RETURN 'Transaction'[OrigAmount] * vRate )Visual:
DataInsights
4 years agoSuper User
Anonymous,
This solution uses a Currency table that functions as a bridge table between the ExchangeRate and Transaction tables. The Currency table can be created in DAX or Power Query. The column ExchangeRate[FxRatePeriod] uses the first day of the month.
Measures:
ConvertedAmount =
SUMX (
'Transaction',
VAR vRate =
MAXX ( RELATEDTABLE ( ExchangeRate ), ExchangeRate[Rate] )
RETURN
'Transaction'[OrigAmount] * vRate
)PrevMonthRateConvertedAmount =
SUMX (
'Transaction',
VAR vCurrency = 'Transaction'[Currency]
VAR vPeriod =
EDATE ( SELECTEDVALUE ( ExchangeRate[FxRatePeriod] ), -1 )
VAR vTable =
FILTER (
ALL ( ExchangeRate ),
ExchangeRate[Currency] = vCurrency
&& ExchangeRate[FxRatePeriod] = vPeriod
)
VAR vRate =
MAXX ( vTable, ExchangeRate[Rate] )
RETURN
'Transaction'[OrigAmount] * vRate
)
Visual: