Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
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:
Thanks in advance!
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;
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;
@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:
Thanks a lot!