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: 
antonopn
Contributor III
Contributor III

Script calculation based on previous values

Hi everyone, 

I am facing a problem with a table I am reading. Table has some average weight ranges, but has only "From" values as below. I would like to calculate "To" column inside the script. Columns "TableID" and SizeID are also coming from the table and I need them.

TableID From To SizeID Calcuation Notes
{3D643767} 900 99999 4 TableID Start -> static value 99999
{3D643767} 900 99999 5 TableID Start -> static value 99999
{3D643767} 900 99999 6 TableID Start -> static value 99999
{3D643767} 800 899,999 4 From changes, has to be (previous(From)-0.001)
{3D643767} 800 899,999 5 From remains, Previous(To)
{3D643767} 800 899,999 6 From remains, Previous(To)
{3D643767} 700 799,999 3 From changes, has to be (previous(From)-0.001)
{3D643767} 700 799,999 4 From remains, Previous(To)
{3D643767} 700 799,999 5 From remains, Previous(To)
{3D643767} 700 799,999 6 From remains, Previous(To)
{3D643767} 600 699,999 2 From changes, has to be (previous(From)-0.001)
{3D643767} 600 699,999 3 From remains, Previous(To)
{3D643767} 600 699,999 4 From remains, Previous(To)
{3D643767} 600 699,999 5 From remains, Previous(To)
{89454FAA} 1200 99999 4 TableID Start -> static value 99999
{89454FAA} 1200 99999 5 TableID Start -> static value 99999
{89454FAA} 1200 99999 6 TableID Start -> static value 99999
{89454FAA} 800 1199,999 4 From changes, has to be (previous(From)-0.001)
{89454FAA} 800 1199,999 5 From remains, Previous(To)
{89454FAA} 800 1199,999 6 From remains, Previous(To)
{89454FAA} 700 799,999 3 From changes, has to be (previous(From)-0.001)
{89454FAA} 700 799,999 4 From remains, Previous(To)
{89454FAA} 700 799,999 5 From remains, Previous(To)
{89454FAA} 700 799,999 6 From remains, Previous(To)

 

I tried some combinations of "if"  with "previous" but did not work. Could someone please help? 

Thank you in advance for devoting  your time

QlikView 

 

Labels (2)
1 Solution

Accepted Solutions
MarcoWedel

 

maybe like this?

MarcoWedel_0-1646685628143.png

table1:
LOAD TableID, 
     From, 
     If(TableID=Previous(TableID),If(From=Previous(From),Peek(To),Previous(From)-0.001),99999) as To, 
     SizeID
FROM [https://community.qlik.com/t5/QlikView-App-Dev/Script-calculation-based-on-previous-values/td-p/1901845] (html, codepage is 1252, embedded labels, table is @1);

View solution in original post

2 Replies
MarcoWedel

 

maybe like this?

MarcoWedel_0-1646685628143.png

table1:
LOAD TableID, 
     From, 
     If(TableID=Previous(TableID),If(From=Previous(From),Peek(To),Previous(From)-0.001),99999) as To, 
     SizeID
FROM [https://community.qlik.com/t5/QlikView-App-Dev/Script-calculation-based-on-previous-values/td-p/1901845] (html, codepage is 1252, embedded labels, table is @1);
antonopn
Contributor III
Contributor III
Author

@MarcoWedel  you are great. I learned the function 'Peek'. Many thanks!