我对 Power BI 还很陌生,并且在我的一个项目中遇到了一些问题。
我有一个计算列,它计算客户在多个时期支付的总保费,确定平均值(总保费/时期数),然后将客户置于“保费区间”。
基本上,我是根据客户花费的金额对他们进行分组。
这是我用于 Premium Band 的 DAX:
Premium Band =
//Set the bands
VAR Rng1 = 0
VAR Rng2 = 50000
VAR Rng3 = 100000
VAR Rng4 = 200000
VAR Rng5 = 600000
//Set the value to band
VAR PremiumSum =
CALCULATE(SUMX(
Inforce_Large, Inforce_Large[GrossPremium_InclVat] * Inforce_Large[ZAR Rate]),
ALLEXCEPT(Inforce_Large, Brokers[Broker Name], Inforce_Large[InsuredName]), Inforce_Large[PaymentFrequency] <> "ONCE OFF" )
VAR Var_Divide =
CALCULATE(DISTINCTCOUNT('Date'[Date]),
ALLEXCEPT(Inforce_Large, Brokers[Broker Name], Inforce_Large[InsuredName]), Inforce_Large[PaymentFrequency] <> "ONCE OFF", Inforce_Large[GrossPremium_ExVat] <> 0)
VAR Value1 = PremiumSum/IF(Var_Divide = 0, 1, Var_Divide)
//Order value by designated bands
VAR Band =
SWITCH( TRUE(),
AND(Value1 >= Rng1, Value1 <= Rng2), "1. " & FORMAT(Rng1, "# ##0") & " - " & FORMAT(Rng2, "# ##0"),
AND(Value1 >= Rng2, Value1 <= Rng3), "2. " & FORMAT(Rng2, "# ##0") & " - " & FORMAT(Rng3, "# ##0"),
AND(Value1 >= Rng3, Value1 <= Rng4), "3. " & FORMAT(Rng3, "# ##0") & " - " & FORMAT(Rng4, "# ##0"),
AND(Value1 >= Rng4, Value1 <= Rng5), "4. " & FORMAT(Rng4, "# ##0") & " - " & FORMAT(Rng5, "# ##0"),
Value1 >= Rng5, "5. " & FORMAT(Rng5, "# ##0") & " +",
"out of range"
)
//Value returned
RETURN
Band
这是可行的,但是我想根据要查看的报告选择的货币使其动态化。
我有一个过滤器,允许用户在“基础货币、南非兰特、美元”之间进行选择。
选择 ZAR 时,将使用上述公式中的波段,选择 USD 时,波段将缩小 (/15) 以适应较低的货币数字。
我使用以下 DAX 进行转换:
Gross Prem InclVAT (Converted) =
VAR SV = SELECTEDVALUE('Ref: Currency Convert'[Currency])
VAR Calc =
SUMX(
Inforce_Large, Inforce_Large[GrossPremium_InclVat]
* SWITCH(TRUE(),
SV = "ZAR", LOOKUPVALUE('Rates ZAR'[Units per ZAR], 'Rates ZAR'[Currency], LOOKUPVALUE('Ref: Currencies'[XE Currency Code], 'Ref: Currencies'[CurrencyDesc], Inforce_Large[Currency])),
SV = "USD", LOOKUPVALUE('Rates USD'[USD per unit], 'Rates USD'[Currency], LOOKUPVALUE('Ref: Currencies'[XE Currency Code], 'Ref: Currencies'[CurrencyDesc], Inforce_Large[Currency])),
1))
RETURN Calc
我意识到我无法在计算列中引用度量。但是,我不确定要尝试什么。 我尝试了各种不同的方法,但都没有得到我需要的结果。
任何建议将不胜感激。 目前我觉得我对自己想要实现的目标很大胆。
亲切的问候, 莫拉利斯