Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Join us to spark ideas for how to put the latest capabilities into action. Register here!
cancel
Showing results for 
Search instead for 
Did you mean: 
samuel_brierley
Creator
Creator

use previous to return value X rows up

Hi all,

thanks for any response, i think the title sums this up perfectly.

in the load script i want to create a field that is

ULO_Count - Previous(ULO_Count)) as [Non-Cumulative],

where previous(ULO_Count) isnt one row up but 20 for example.

thanks

1 Solution

Accepted Solutions
sunny_talwar

Not sure how your data is, but may be something like this:

Table:

LOAD * INLINE [

    Cum

    5

    5

    5

    5

    30

    30

    32

    32

    32

    32

    32

    32

    32

    40

    40

    41

    43

    43

    43

    50

];

Table2:

LOAD Cum,

  Alt(Cum - Peek('Cum'), Cum) as NonCum

Resident Table;

DROP Table Table;

Best,

S

View solution in original post

4 Replies
Gysbert_Wassenaar
Partner - Champion III
Partner - Champion III

Use the peek function: peek(ULO_Count,-20)


talk is cheap, supply exceeds demand
samuel_brierley
Creator
Creator
Author

will not that always return the 20th row from the bottom of the table?

Gysbert_Wassenaar
Partner - Champion III
Partner - Champion III

That depends on where it is used. If you use it in a load statement it will get the value from the 20th previous row. If you use it to create a variable then the table was already created and you get the value from the 20th row from the bottom. Try this script and compare the values of B with the variable vMyValue.

T1:

LOAD recno() as A, peek(A, -20) as B

autogenerate(100);

LET vMyValue = peek('A', -20, 'T1');


talk is cheap, supply exceeds demand
sunny_talwar

Not sure how your data is, but may be something like this:

Table:

LOAD * INLINE [

    Cum

    5

    5

    5

    5

    30

    30

    32

    32

    32

    32

    32

    32

    32

    40

    40

    41

    43

    43

    43

    50

];

Table2:

LOAD Cum,

  Alt(Cum - Peek('Cum'), Cum) as NonCum

Resident Table;

DROP Table Table;

Best,

S