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

Announcements
Join us in Toronto Sept 9th for Qlik's AI Reality Tour! Register Now
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

How to calculate the cumulative sum in a 3 dimensions table?

Hello to all,

I'm looking for the formula to calculate the cumulative sum in a table with 3 dimensions.

For clarity I attach an example of the results that I would get.

Thanks to everyone who can help me.

YearMonthAgentSum(Amount) ?
20121A100100
20121B8080
20122A100200
20122B80160
20123A100300
20123B80240
20124A100400
20124B80320
20125A100500
20125B80400
20126A100600
20126B80480
20127A100700
20127B80560
20128A100800
20128B80640
20129A100900
20129B80720
201210A1001000
201210B80800
201211A1001100
201211B80880
201212A1001200
201212B80960
2 Replies
Not applicable
Author

Maybe not the prettiest expression, but you could try this:

If(Agent='A', RangeSum(Above(TOTAL Sum({$<Agent*={A}>}Amount), 0, RowNo(TOTAL)))

,If(Agent='B', RangeSum(Above(TOTAL Sum({$<Agent*={B}>}Amount), 0, RowNo(TOTAL)))))

Not applicable
Author

Thank you Anton, your response functions in this specific case, but I'd like to find a more generic formula, something that works regardless of the number of elements in the third dimension.

Also I would like the values ​​come back to zero when the year changes.

Here below is the table that results from your formula.

YearMonthAgentIf(Agent='A', RangeSum(Above(TOTAL Sum({$<Agent*={A}>}Amount), 0, RowNo(TOTAL)))
,If(Agent='B', RangeSum(Above(TOTAL Sum({$<Agent*={B}>}Amount), 0, RowNo(TOTAL)))))
20121A100
20121B80
20122A200
20122B160
20123A300
20123B240
20124A400
20124B320
20125A500
20125B400
20126A600
20126B480
20127A700
20127B560
20128A800
20128B640
20129A900
20129B720
201210A1000
201210B800
201211A1100
201211B880
201212A1200
201212B960
20131A1270
20131B1070
20132A1340
20132B1180
20133A1410
20133B1290
20134A1480
20134B1400
20135A1550
20135B1510
20136A1620
20136B1620
20137A1690
20137B1730
20138A1760
20138B1840
20139A1830
20139B1950
201310A1900
201310B2060
201311A1970
201311B2170
201312A2040
201312B2280