Skip to main content
Announcements
Introducing Qlik Answers: A plug-and-play, Generative AI powered RAG solution. READ ALL ABOUT IT!
cancel
Showing results for 
Search instead for 
Did you mean: 
Touyets
Contributor II
Contributor II

Detect and Evaluate changes in snapshot in Load Script

Hi all,

 

I have a load script that is taking data from SQL in a snapshot format. So we have a table where for our items like this:

ITEM_IDSNAPSHOT_DTAmountFlag: Change in amount?Change in AmountTotal ValueFlag: Change in total value?Change in total value
122/06/20192Y+1$100Y+$25
115/06/20191N0$75N$0
108/06/20191N0$75N$0
222/06/201910N0$350N$0
322/06/20195Y-15$250Y-$550
315/06/201920N0$800N$0

 

I marked in the red the columns I wish to create. So for example, the first 3 rows belong to the same item ID ordered by Snapshot date and you can see that item's amount and value change over time.

 

How do I have each row look for its predecessor and see if that item has changed in either amount or value and then calculate the change in the QS load script editor?

Labels (3)
1 Solution

Accepted Solutions
LeHaoNguyen
Contributor III
Contributor III

ye wrap that around an if statement IF(item_id = peek(item_id),.....)

View solution in original post

5 Replies
LeHaoNguyen
Contributor III
Contributor III

You can load with an orderby item_id, Snapshot_DT and then use peek function to check the previous row:

https://help.qlik.com/en-us/sense/1.0/Subsystems/WorkingWith/Content/Scripting/InterRecordFunctions/...

Touyets
Contributor II
Contributor II
Author

Would that not take the previous record regardless of the Item_ID? So Item 1 might end up comparing its line to the previous row even though that previous row is for a different item? I haven't seen any filtering options for the peek function so far.

LeHaoNguyen
Contributor III
Contributor III

ye wrap that around an if statement IF(item_id = peek(item_id),.....)

Touyets
Contributor II
Contributor II
Author

Actually... I could combine 2 peek formulas and an IF() statement. have it check if the previosu row is for the same ID using peek and then it could take the previous value...

IF (PEEK(ITEM_ID)<>ITEM_ID,NULL, PEEK(VALUE) - VALUE) AS ChangeInValue
Touyets
Contributor II
Contributor II
Author

yup, I got there in the end thanks to your help!