I'm trying to add two columns with static value RM500 it gives us a new column called totalSA
My Table is:
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
Expected Table is:
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
Logic: if Policy no is the same then we need to increment.
(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
I have tried the below code doesn't work.
Total_SA =
VAR insSA = CONVERT(SUBSTITUTE([Incremental SA], "RM", ""),INTEGER)
VAR refSA = CONVERT(SUBSTITUTE([Referral SA],"RM",""),INTEGER)
VAR PreviousRow =
TOPN (
1,
FILTER (
'Table',
'Table'[Index] < EARLIER('Table'[Index]) &&
'Table'[Pol No.] = EARLIER ( 'Table'[Pol No.])
),
[Index], DESC
)
VAR PreviousValue = MAXX( PreviousRow,CONVERT(SUBSTITUTE('Table'[Referral SA], "RM", ""),INTEGER) )
RETURN PreviousValue + CONVERT(SUBSTITUTE('Table'[Incremental SA], "RM", ""),INTEGER) + 500
As you said you have an Index column in the table, let your data looks like below-
Now, create this following Measure in the table-
Here is your final output-