使用DAX-我需要使用缓慢变化的维度作为来源来计算具有某种状态的保单的总保费金额。
这是在SSAS表格模型中运行的东西。
解决方案有两个表-dim_date(这是日历表)和Dim_contract(列出了我的所有策略) Dim_Contract表是一个变化缓慢的维度。
表格格式:
DW_ContractID DW_EffectiveFromDate contract_number actual_recurring_collection ContractStatusTLA
-2145825896 22 August 2018 4303140 80 PIN
-2145627139 26 September 2018 4303140 80 INF
-2145428382 09 October 2018 4303140 80 Can
-2145229625 21 August 2018 4303142 100 PIN
-2145030868 22 September 2018 4303142 100 NTU
-2144832111 02 September 2018 4303999 50 PIN
-2144633354 03 September 2018 4303999 50 INF
我已经进行了计算以计算策略-效果100%。 通过此计算,我们可以计算每个时间段的策略数量。 (取决于用户选择的内容)
示例-如果我们要计算每种状态截至9月底的保单数量,我们应该得到:
INF: 2 (This is counting policy numbers 4303140 and 4303999 as their last status is INF)
CAN: 0
NTU: 1
用于计数的代码:
PolicyCount_NTU :=
IF (
MIN ( DIM_Date[Date] )
>= CALCULATE ( MIN ( DIM_Contract[DW_EffectiveFromDate] ), ALL ( DIM_Contract ) ),
IF (
MIN ( DIM_Date[Date] )
<= CALCULATE ( MAX ( DIM_Contract[DW_EffectiveFromDate] ), ALL ( DIM_Contract ) ),
CALCULATE (
COUNTROWS (
FILTER (
DIM_Contract,
DIM_Contract[DW_ContractID]
= CALCULATE (
MAX ( DIM_Contract[DW_ContractID] ),
ALL ( DIM_Contract ),
DIM_Contract[contract_number] = EARLIER ( DIM_Contract[contract_number] ),
( DIM_Contract[DW_EffectiveFromDate] ) <= VALUES ( DIM_Date[Date] )
)
)
),
LASTDATE ( DIM_Date[Date] ),
DIM_Contract[ContractStatusTLA] = "NTU"
)
)
)
问题来自calc以获取金额的总和... 我使用了这段代码:
PolicyAPI_NTU :=
IF (
MIN ( DIM_Date[Date] )
>= CALCULATE ( MIN ( DIM_Contract[DW_EffectiveFromDate] ), ALL ( DIM_Contract ) ),
IF (
MIN ( DIM_Date[Date] )
<= CALCULATE ( MAX ( DIM_Contract[DW_EffectiveFromDate] ), ALL ( DIM_Contract ) ),
CALCULATE (
SUM ( DIM_Contract[actual_recurring_collection] ),
(
FILTER (
DIM_Contract,
DIM_Contract[DW_ContractID]
= CALCULATE (
MAX ( DIM_Contract[DW_ContractID] ),
ALL ( DIM_Contract ),
DIM_Contract[contract_number] = EARLIER ( DIM_Contract[contract_number] ),
DIM_Contract[DW_EffectiveFromDate] < VALUES ( DIM_Date[Date] )
)
)
),
LASTDATE ( DIM_Date[Date] ),
DIM_Contract[ContractStatusTLA] = "NTU"
)
)
)
使用最后一段代码获取金额的总和不起作用-我得到一个错误:错误:度量'DIM_Contract'[PolicyAPI_NTU]中的计算错误:提供了多个值表,其中单个值是预期的。
答案 0 :(得分:0)
我怀疑您的问题在这里
explode
如果DIM_Contract[DW_EffectiveFromDate] < VALUES ( DIM_Date[Date] )
有多个值,则DAX不知道如何进行比较。
尝试使用DIM_Date[Date]
或MAX
或MIN
或类似的方法代替LASTDATE
。