Skip to main content
Announcements
See why Qlik is a Leader in the 2024 Gartner® Magic Quadrant™ for Analytics & BI Platforms. Download Now
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

PREVIOUS() function in load script

Hi,

I would like to return the previous value (grouped by product). AND I would like to do it in load script. I have a partial solution, but it is not very elegant or efficient. How this could be done?

Thanks!

1 Solution

Accepted Solutions
jyothish8807
Master II
Master II

Hi user,

PFA updated one.

Regards

KC

Best Regards,
KC

View solution in original post

7 Replies
ashfaq_haseeb
Champion III
Champion III

Look at peek and previous function.

Regards

ASHFAQ

Not applicable
Author

But peek gets only the row (and table) as input argument. So it doesn't work when the product changes, right?

"Peek() is used in the script, pick()  - on the front end.  From Help:

peek(fieldname [ , row [ , tablename ] ] )

Returns the contents of the fieldname in the record specified by row in the internal table tablename. Data are fetched from the associative QlikView database.

Fieldname must be given as a string (e.g. a quoted literal).

Row must be an integer. 0 denotes the first record, 1 the second and so on. Negative numbers indicate order from the end of the table. -1 denotes the last record read.

If no row is stated, -1 is assumed.

Tablename is a table label, see Table Labels, without the ending colon. If no tablename is stated, the current table is assumed. If used outside the load statement or referring to another table, the tablename must be included. "

jyothish8807
Master II
Master II


Hi user,

PFA. is this is what you are looking for?

Regards

KC

Best Regards,
KC
jyothish8807
Master II
Master II

Change the line to.

if(Product= previous(Product),previous(Price),'') as Pre_price

Regards

KC

Best Regards,
KC
jyothish8807
Master II
Master II

Hi user,

PFA updated one.

Regards

KC

Best Regards,
KC
anbu1984
Master III
Master III

Initial:

Load DATE(DATE#(DATE,'M.D.YYYY')) AS DATE,PRODUCT,PRICE INLINE [

DATE,PRODUCT,PRICE

1.1.2014,A,30

1.2.2014,A,30

1.3.2014,A,29

1.1.2014,B,43

1.2.2014,B,43

1.3.2014,B,40 ];

NoConcatenate

Final:

Load DATE,PRODUCT,PRICE,If(PRODUCT = Previous(PRODUCT),PRICE) as PREV_PRICE Resident Initial Order by PRODUCT,DATE;

Drop table Initial;

Not applicable
Author

Of course! It's so simple, thanks!