问题描述
我正尝试添加两个静态值RM500的列,这为我们提供了一个名为totalSA的新列
我的表格是:
200
messageOK
{"message":"success","data":["query execution time : 677.0.....]}
200
messageOK
{"message":"success","data":["query execution time : 19.0.....]}
200
messageOK
{"message":"success","data":["query execution time : 18.0.....]}
200
messageOK
{"message":"success","data":["query execution time : 129.0.....]}
200
messageOK
{"message":"success","data":["query execution time : 39.0.....]}
200
messageOK
{"message":"success","data":["query execution time : 17.0.....]}
200
messageOK
{"message":"success","data":["query execution time : 197.0.....]}
200
messageOK
{"message":"success","data":["query execution time : 41.0.....]}
200
messageOK
{"message":"success","data":["query execution time : 20.0.....]}
200
messageOK
{"message":"success","data":["query execution time : 13.0.....]}
预期表为:
Transaction Date Pol No. Policy Status Incremental SA Referral SA
16-Sep-20 P00061353 Inforce RM100 0
17-Sep-20 P00061353 Inforce RM100 0
18-Sep-20 P00061353 Inforce RM100 0
18-Sep-20 P00061353 Inforce RM100 RM200
19-Sep-20 P00061353 Inforce RM100 0
18-Sep-20 P00061354 Inforce RM100 0
18-Sep-20 P00061354 Inforce RM100 RM200
19-Sep-20 P00061354 Inforce RM100 0
逻辑:如果“策略号”相同,则需要增加。
Transaction Date Pol No. Policy Status Incremental SA Referral SA Total SA
16-Sep-20 P00061353 Inforce RM100 0 RM600
17-Sep-20 P00061353 Inforce RM100 0 RM700
18-Sep-20 P00061353 Inforce RM100 0 RM800
18-Sep-20 P00061353 Inforce RM100 RM200 RM1100
19-Sep-20 P00061353 Inforce RM100 0 RM1200
18-Sep-20 P00061354 Inforce RM100 0 RM600
18-Sep-20 P00061354 Inforce RM100 RM200 RM900
19-Sep-20 P00061354 Inforce RM100 0 RM1000
我尝试了以下代码不起作用。
(Initial value/previous toal)+Incremental SA + Referral SA Total SA
RM500 + RM100 +0 RM600 (New Policy)
RM600 + RM100 +0 RM700
RM700 + RM100 +0 RM800
RM800 + RM100 +RM200 RM1100
RM1100 + RM100 +0 RM1200
RM500 + RM100 +0 RM600 (New Policy)
RM600 + RM100 +RM200 RM900
RM900 + RM100 +0 RM1000
解决方法
就像您说的那样,表中有一个索引列,让您的数据如下所示-
现在,在表中的测量之后创建此表-
total_sa =
var initial_amount = 500
var current_index = MIN('Table'[Index])
var cumulative_inc_sa =
CALCULATE(
SUM('Table'[Incremental SA]),FILTER(
ALL('Table'),'Table'[Index] <= current_index
)
) + 0
var cumulative_ref_sa =
CALCULATE(
SUM('Table'[Referral SA]),'Table'[Index] <= current_index
)
) + 0
RETURN initial_amount + cumulative_inc_sa + cumulative_ref_sa
这是您的最终输出-
,在您的示例中,并假设所有事务均按索引排序,这看起来像一个简单的总计:
Total_SA =
VAR currentIndex = SELECTEDVALUE('Table'[Index])
RETURN
CONCATENATE("RM",CONVERT(
CALCULATE(SUM(CONVERT(SUBSTITUTE('Table'[Incremental SA],"RM",""),INTEGER))
+ SUM(CONVERT(SUBSTITUTE('Table'[Referral SA],INTEGER)),ALL('Table'),'Table'[Index] <= currentIndex
) + 500,STRING))
我建议您另外使用SA的int值创建2列,因为这会使代码更具可读性。