Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Qlik GA: Multivariate Time Series in Qlik Predict: Get Details
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Cummulative Calculation based on condition

Hi All,

I am stuck in one of the requirement and I am not able to find the right solution.

  

IDSeqCategoryAmount
11a100
12a200
13a300
14b200
15c150
26c300
27a100
28b100
29b300
210a175

I need output like below

  

IDSeqCategoryAmountCummulative
11a100100
12a200200
13a300300
14b200400“(100+200+300)-200”
15c150850“(100+200+300+400)-150”
26c300300
27a1002050“(100+200+300+400+850+300)-100”
28b1004400
29b300300
210a1758725

So basically when Category is Same, amount will be same, but when category changed sequentially (eg. Seq=4) , amount should be calculated as (sum of all previous category amount - current category amount)

Hope I have explained the logic well.

gwassenaar  swuehlsunindiakush141087

11 Replies
perumal_41
Partner - Specialist II
Partner - Specialist II

alternative solution

Temp1:
LOAD * INLINE [
ID, Seq, Category, Amount
1, 1, a, 100
1, 2, a, 200
1, 3, a, 300
1, 4, b, 200
1, 5, c, 150
2, 6, c, 300
2, 7, a, 100
2, 8, b, 100
2, 9, b, 300
2, 10, a, 175
]
;

Temp2:
Load * ,if(RowNo()=1,Amount,if (Category=Peek(Category), Peek(Cum)+Amount,Peek(Cum)+Peek(Cum)-Amount)) as Cum,if(RowNo()<>1 and Category <> peek(Category), Amount,0) as Deu Resident  Temp1;


Load *,if(RowNo()=1,Cum,if(Category<>Peek(Category),Cum-Peek(Cum),Amount)) as Cum1 Resident Temp2;

DROP Table Temp1,Temp2;

Not applicable
Author

thanks all.. and specially qlik superhero swuehl