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

Announcements
Qlik and ServiceNow Partner to Bring Trusted Enterprise Context into AI-Powered Workflows. Learn More!
cancel
Showing results for 
Search instead for 
Did you mean: 
bartwelvaarts
Contributor III
Contributor III

calculate cumulative with group by

Hello friends of the qlik community,

i want to calculate the cumulative in combination with a group by, but i do not get the desired output. Does someone know a solution to get the desired output. See example below:

 

bartwelvaarts_0-1605531523617.png

Thanks in advance!

 

1 Solution

Accepted Solutions
QFabian
MVP
MVP

Hi @bartwelvaarts , here you have an example, it uses peek() and previous() funcions , to handle inter records:

Data:
Load * Inline [
time, Product, Customer, Amount
15:00,x,a,200
16:00,x,a,100
15:00,z,b,50
16:00,z,b,60
15:00,y,c,80
];

Load
Product & ' | ' & Customer as %_Key,

time,
Product,
Customer,
Amount,
if(Product = previous(Product) and Customer = previous(Customer), peek(Total) + Amount,Amount) as Total

Resident Data;


drop table Data;

Greetings!! Fabián Quezada (QFabian)
did it work for you? give like and mark the solution as accepted.

View solution in original post

3 Replies
QFabian
MVP
MVP

Hi @bartwelvaarts , here you have an example, it uses peek() and previous() funcions , to handle inter records:

Data:
Load * Inline [
time, Product, Customer, Amount
15:00,x,a,200
16:00,x,a,100
15:00,z,b,50
16:00,z,b,60
15:00,y,c,80
];

Load
Product & ' | ' & Customer as %_Key,

time,
Product,
Customer,
Amount,
if(Product = previous(Product) and Customer = previous(Customer), peek(Total) + Amount,Amount) as Total

Resident Data;


drop table Data;

Greetings!! Fabián Quezada (QFabian)
did it work for you? give like and mark the solution as accepted.
Taoufiq_Zarra

@bartwelvaarts  May be this :

Table1:

load autonumber(Product&Customer) as Idtmp1,rowno() as Idtmp2,*

 inline [
time,Product,Customer,Amount
15:00,x,a,200
16:00,x,a,100
15:00,z,b,50
16:00,z,b,60
15:00,y,c,80
];

output:
noconcatenate

load *,if(Product=peek(Product) and Customer=peek(Customer),peek(Total)+Amount,Amount) as Total;
load * resident Table1 order by Idtmp1,Idtmp2;

drop table Table1;
drop fields Idtmp1,Idtmp2;

to change INLINE [...] by  ... From [Source] (qvd)

 

output:

Taoufiq_Zarra_0-1605535083943.png

 

Regards,
Taoufiq ZARRA

"Please LIKE posts and "Accept as Solution" if the provided solution is helpful "

(you can mark up to 3 "solutions") 😉
bartwelvaarts
Contributor III
Contributor III
Author

Thanks  a lot!