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

Announcements
Qlik Open Lakehouse is Now Generally Available! Discover the key highlights and partner resources here.
cancel
Showing results for 
Search instead for 
Did you mean: 
mmilani12
Contributor
Contributor

Cumulative Sum in Qlikview Script

Hi everyone,

in the script I need to find a formula to obtain from this table:

date                                   art                sales

01/03/2020                      011             20

03/03/2020                      011             10

04/03/2020                      011             5

05/03/2020                      011             10

06/03/2020                      011             30

the column cumulative as below:

date                                   art                sales      cumulative

01/03/2020                      011             20               20

03/03/2020                      011             10               30

04/03/2020                      011             5                 35

05/03/2020                      011             10               45

06/03/2020                      011             30               75

I can't find a solution! Please consider this is just a example, the original table has thousands of rows.

1 Solution

Accepted Solutions
sunny_talwar

Try a script like this

Table:
LOAD * INLINE [
    Date, Art, Sales
    01/03/2020, 011, 20
    03/03/2020, 011, 10
    04/03/2020, 011, 5
    05/03/2020, 011, 10
    06/03/2020, 011, 30
    01/03/2020, 022, 40
    03/03/2020, 022, 5
    04/03/2020, 022, 10
    05/03/2020, 022, 5
    06/03/2020, 022, 60
];

FinalTable:
LOAD Date,
	 Art,
	 Sales,
	 If(Art = Previous(Art), RangeSum(Peek('Cumulative Sales'), Sales), Sales) as [Cumulative Sales]
Resident Table
Order By Art, Date;

DROP Table Table;

View solution in original post

2 Replies
sunny_talwar

Try a script like this

Table:
LOAD * INLINE [
    Date, Art, Sales
    01/03/2020, 011, 20
    03/03/2020, 011, 10
    04/03/2020, 011, 5
    05/03/2020, 011, 10
    06/03/2020, 011, 30
    01/03/2020, 022, 40
    03/03/2020, 022, 5
    04/03/2020, 022, 10
    05/03/2020, 022, 5
    06/03/2020, 022, 60
];

FinalTable:
LOAD Date,
	 Art,
	 Sales,
	 If(Art = Previous(Art), RangeSum(Peek('Cumulative Sales'), Sales), Sales) as [Cumulative Sales]
Resident Table
Order By Art, Date;

DROP Table Table;
m_woolf
Master II
Master II

Something like:

Load
          Date,
          Art,
          Sales,
          If(Peek('Art')=Art,Sales,Peek('Cummulative'),Rangesum(Sales,Cummulative)) as Cummulative
from Whatever
order by Date,Art;