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

Cumulative sum with two dimension.


Hi everybody, Could you Please help me in finding solution for this problem. I am attaching the data sheet with the problem.

I have a date field and an Amount field.

DateAmount
01-Apr-12100
01-May-12200
01-Jun-12300
01-Jul-12400
01-Aug-120
01-Sep-12100
01-Oct-120
01-Nov-12120
01-Dec-12100
01-Jan-13200
02-Jan-131500
01-Mar-13200
01-Apr-13100
01-May-13100
01-Jun-13100

I have  to show the data in a straight table as cumulative sum of Amount.

the Conditions are:

Here the cumulative sum of 3rd row will be sum of 3rd 2nd and 1st Amount.
The year starts at April and ends at March so when April 2013 comes, the sum should start again.
The value 0 should be displayed in the chart.

DateAmountCumulative
01-Apr-12100100
01-May-12200300
01-Jun-12300600
01-Jul-124001000
01-Aug-1201000
01-Sep-121001100
01-Oct-1201100
01-Nov-121201220
01-Dec-121001320
01-Jan-132001520
02-Jan-132001720
01-Mar-132001920
01-Apr-13100100
01-May-13100200
01-Jun-13100300

Can it be done. If I remove the Amount field. I can easily get the cumulative sum. But adding Amount dimension creates a problem.

1 Solution

Accepted Solutions
Not applicable
Author

I got the solution for it. If we take year as a seperate field in load statement like shown below.

LOAD Date,

Year(Date),

if(Month(Date)='Jan',Year(Date)-1,if(Month(Date)='Feb',Year(Date)-1,if(Month(Date)='Mar',Year(Date)-1,Year(Date)))) as FY,

Amount

FROM

CUMULATIVE.xlsx.

Now in a chart i.e straight table take Date as dimension, FY as dimension, Amount as Expression and Sum(Amount)  as Expression.

Make sure the Accmulation is checked and Hide Fy . You can get the desired result set.

View solution in original post

4 Replies
mrybalko
Creator II
Creator II

I suggest to calculate cumulative sum by loading script.

Two tips:

Calculate finance year

year(AddMonths(Date, -3)) as FinanceYear

Then use functions previous and peek to calculate cumulative sum

if(FinanceYear=Previous(FinanceYear),

  peek('CumulativeAmount') + Amount,

  Amount) as CumulativeAmount

Example in attachment.

Not applicable
Author

Thanks Maxim

Thanks a lot.

Not applicable
Author

I got the solution for it. If we take year as a seperate field in load statement like shown below.

LOAD Date,

Year(Date),

if(Month(Date)='Jan',Year(Date)-1,if(Month(Date)='Feb',Year(Date)-1,if(Month(Date)='Mar',Year(Date)-1,Year(Date)))) as FY,

Amount

FROM

CUMULATIVE.xlsx.

Now in a chart i.e straight table take Date as dimension, FY as dimension, Amount as Expression and Sum(Amount)  as Expression.

Make sure the Accmulation is checked and Hide Fy . You can get the desired result set.

Not applicable
Author

Just to clean that up a bit:

LOAD

Date,

Year(Date)

if(Num(Month(Date))<=3,Year(Date)-1,Year(Date) As FY,

etc.