Skip to main content
Announcements
Qlik Introduces a New Era of Visualization! READ ALL ABOUT IT
cancel
Showing results for 
Search instead for 
Did you mean: 
itatspectrum
Partner - Contributor II
Partner - Contributor II

Previous and Peek not working.

Hello, 

I'm having trouble getting Previous and Peek to work on a simple data set. 

I'm trying to get the cumulative Minutes in the production plan as a start. 

But for some reason the extract I get seems to stop cumulating after the 2nd row!

Red is what Qlik is giving me at present, green is what I'm after. 

Any help appreciated. 

Steve

Screenshot 2022-03-06 at 00.37.19.png

PlanTMP:
LOAD
Machine,
timestamp("Sched. start") as "Sched. start",
Plan_Minutes
FROM [lib://QLIK-DATA/CSV/INJECTION.csv]
(txt, codepage is 28591, embedded labels, delimiter is ',', msq) ;

Plan:
Load
*,
if(previous(Machine)<>Machine,Plan_Minutes,peek(Plan_Minutes)+Plan_Minutes) as [Machine Check], 
if(previous(Machine)=Machine,peek(Plan_Minutes)+Plan_Minutes,Plan_Minutes) as Cumulative

Resident PlanTMP Order by Machine,"Sched. start" asc;

DROP Table PlanTMP;

Labels (1)
1 Reply
rubenmarin

Hi, you need to add the the previous cumulative, not the plan_minutes:

if(previous(Machine)=Machine,peek(Cumulative)+Plan_Minutes,Plan_Minutes) as Cumulative

I also use Rangesum() that converts Nulls to zero:

if(previous(Machine)=Machine,Rangesum(peek(Cumulative),Plan_Minutes),Plan_Minutes) as Cumulative