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

Announcements
Want to see what's currently in public preview? We've pulled it all together in one place. Check it out here
cancel
Showing results for 
Search instead for 
Did you mean: 
Øystein_Kolsrud
Employee
Employee

Load cumulativ data

I often have cases where I want to analyze cumulative data across a table. A typical example is that I want to display cumulative quarterly sales per year when my input data contains data regarding sales per quarter. So I would like to take this input:

YearQuarterSales
202011
202022
202037
202042
202118
202121
202131
202143

 

And get this table:

YearQuarterSalesCumulative Sales
2020111
2020223
20203710
20204212
2021188
2021219
20213110
20214313

 

What is the best way to do this in the script?

1 Solution

Accepted Solutions
MarcoWedel
MVP
MVP

one solution might be:

MarcoWedel_0-1637873440283.png

tabSales:
LOAD Year, 
     Quarter, 
     Sales,
     RangeSum(Sales,If(Year=Previous(Year),Peek(CumulativeSales))) as CumulativeSales
FROM [https://community.qlik.com/t5/App-Development/Load-cumulativ-data/m-p/1863624] (html, codepage is 1252, embedded labels, table is @1);

 

hope this helps

Marco

View solution in original post

2 Replies
MarcoWedel
MVP
MVP

one solution might be:

MarcoWedel_0-1637873440283.png

tabSales:
LOAD Year, 
     Quarter, 
     Sales,
     RangeSum(Sales,If(Year=Previous(Year),Peek(CumulativeSales))) as CumulativeSales
FROM [https://community.qlik.com/t5/App-Development/Load-cumulativ-data/m-p/1863624] (html, codepage is 1252, embedded labels, table is @1);

 

hope this helps

Marco

Øystein_Kolsrud
Employee
Employee
Author

Nice! Thank you very much for the solution! I actually didn't realize I could use Peek and refer to a field that doesn't exist. I would assume it would return a "Field 'CumulativeSales' not found" error on the first row, but I see now that the Peek function returns 'null' whenever a field is non-existent.