Qlik Community

Ask a Question

QlikView App Dev

Discussion Board for collaboration related to QlikView App Development.

Announcements
On May 18th at 10AM EDT we will answer your QlikView questions live. REGISTER
cancel
Showing results for 
Search instead for 
Did you mean: 
vigneshea
Contributor III
Contributor III

How to Calculate Accumulative sum for Separate products with Script?

Task1.PNG

I have a table, I need to show the cumulative sum of the 'Total' column for each products. For example: If i select product 'B' then i should the get the cumulative sum of Product B alone with respective date. i.e 15+2+3=20 not 47+49+52.

I need Output as Below.

b4.PNG

Not Like this

b3.PNG

1 Solution

Accepted Solutions
sunny_talwar

May be like this

LOAD Date,

      Product,

     Quantity,

     If(Product = Previous(Product), RangeSum(Peek('Total'), Quantity), Quantity) as Total

Resident ....

Order By Product, Date Asc;

View solution in original post

10 Replies
sunny_talwar

May be like this

LOAD Date,

      Product,

     Quantity,

     If(Product = Previous(Product), RangeSum(Peek('Total'), Quantity), Quantity) as Total

Resident ....

Order By Product, Date Asc;

View solution in original post

shiveshsingh
Master
Master

plz try this

T:LOAD *,Date#(Date,'DD-MM-YYYY') as Date_N INLINE [

    Date, Product, Quantity

    10-12-2015, A, 1

    11-12-2015, A, 2

    12-12-2015, A, 3

    13-12-2015, A, 4

    14-12-2015, B, 3

    15-12-2015, B, 5

    16-12-2015, B, 6

     17-12-2015, C, 10

    19-12-2015, C, 12

];

load *, if(rowno()=1, Quantity, if(Product = Previous(Product), RangeSum(Quantity, Peek(Total)),Quantity))as Total

Resident T

order by Product, Date_N asc

;

sunny_talwar

Do we really need RowNo() = 1 check? Product will not be equal to Previous(Product) which you already gives Quantity, why add the RowNo() condition

shiveshsingh
Master
Master

Not actually, my bad

Sorry bro

sunny_talwar

no sorry needed, just fyi

vigneshea
Contributor III
Contributor III
Author

Thanks bro, Got the Answer

vigneshea
Contributor III
Contributor III
Author

Thanks bro

jyothish8807
Master II
Master II

Just one more approach

load  Date,

      Product,

     Quantity,

     If(Product = Previous(Product), Peek('Total')+ Quantity, Quantity) as Total

Resident Table

order by Product, Date asc;

Br,

KC

Best Regards,
KC
vigneshea
Contributor III
Contributor III
Author

Thanks for the answer bro