我有一个示例代码如下。我想找到每种货币的汇率乘以其金额。
Curreny Amount
usd 100
eur 75
cny 50
eur 25
jpy 25
预期答案
100*1 + 75*0.9 + 50*0.5 + 25*0.9 + 25*0.7
我想做的不起作用的是:
_RateMeasure1 =
VAR CurrencyAmounts = SUMMARIZE('myDF',myDF[Currency], 'myDF'[Amount])
VAR USD_Rate = MAXX(FILTER('_SlicerTable', _SlicerTable[Currency] = "USD"), '_SlicerTable'[RateCol1])
VAR EUR_Rate = MAXX(FILTER('_SlicerTable', _SlicerTable[Currency] = "EUR"), '_SlicerTable'[RateCol1])
VAR CNY_Rate = MAXX(FILTER('_SlicerTable', _SlicerTable[Currency] = "CNY"), '_SlicerTable'[RateCol1])
VAR JPY_Rate = MAXX(FILTER('_SlicerTable', _SlicerTable[Currency] = "JPY"), '_SlicerTable'[RateCol1])
RETURN
SUMX(
CurrencyAmounts,
SWITCH(
myDF[Currency],
"USD", 'myDF'[Amount] * USD_Rate,
"EUR", 'myDF'[Amount] * EUR_Rate,
"CNY", 'myDF'[Amount] * CNY_Rate,
"JPY", 'myDF'[Amount] * JPY_Rate
)
)
_SlicerTable是一个如下表
Currency RateCol1
USD 1
CNY 0.5
EUR 0.9
JPY 0.7
这可以通过以下方式完成:
_RateMeasure = SUMX(myDF,myDF[Amount]*RELATED('货币转换'[RateCol1])) --sumx 是一个迭代器函数,逐行进行。相关参考相关专栏RateCol1