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: 
ksharpes
Creator
Creator

If statement using Peek

Within Script I wish to use the following formula

if([Stock Qty]-[Sales Qty (All)]>Peek([Stock Qty],-1),'Restocked','') as RestockedEVER

Below is my current script which I thought should work however i only get null values for [RestockedEVER]

NEWTABLEx:
Load Item_ID,
[Stock Qty],
[Sales Qty (All)],
[Reporting Date]

Resident Data_Values_New_2
order by [Item_ID], [Reporting Date];

NEWTABLEy:
NoConcatenate Load Item_ID,
[Reporting Date],
if([Stock Qty]-[Sales Qty (All)]>Peek([Stock Qty],-1),'Restocked','') as RestockedEVER

Resident NEWTABLEx;


NEWTABLE2:
mapping Load Item_ID,
MAX(RestockedEVER) As RestockedEVER
Resident NEWTABLEy
Group by Item_ID;

 

 

Example Data

 

 

Item_IDStock QtySales Qty (All)Reporting Date
1100031/01/2019
1901028/02/2019
11201031/03/2019
11101030/04/2019
11001031/05/2019
2100031/01/2019
2901028/02/2019
21201031/03/2019
21101030/04/2019
21001031/05/2019
31001031/01/2019
3901028/02/2019
3801031/03/2019
3701030/04/2019
3601031/05/2019
41001031/01/2019
4901028/02/2019
4801031/03/2019
4701030/04/2019
4601031/05/2019
1 Solution

Accepted Solutions
lorenzoconforti
Specialist II
Specialist II

Instead of  Peek([Stock Qty],-1) use Previous([Stock Qty])

View solution in original post

1 Reply
lorenzoconforti
Specialist II
Specialist II

Instead of  Peek([Stock Qty],-1) use Previous([Stock Qty])