Skip to main content
Announcements
Qlik Connect 2024! Seize endless possibilities! LEARN MORE
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Peek function in load script

Hello,

Here is a simple load :

Temp:

LOAD * INLINE [

id, field, counter

1, bla,0

1, bla,0

1, bla,0

2, bla,0

2, bla,0

2, bla,0

3, bla,0

3, bla,0

];

Temp2:

LOAD

id,

field,

IF (peek(id)<>id,1, peek(counter) + 1) AS counter2

RESIDENT Temp

ORDER BY id;

drop table Temp;

I try to get a counter which reset for each new id find

I get only 1 for each new id, but it doesn't increment when he find 2 same id :

Sans titre.png

Any idea ?

Thanks

1 Solution

Accepted Solutions
MK_QSL
MVP
MVP

Temp:

LOAD * INLINE [

id, field, counter

1, bla,0

1, bla,0

1, bla,0

2, bla,0

2, bla,0

2, bla,0

3, bla,0

3, bla,0

];

Temp2:

LOAD

id,

field,

IF (Previous(id)<>id,1, peek(counter2) + 1) AS counter2

RESIDENT Temp

ORDER BY id;

drop table Temp;

View solution in original post

4 Replies
MK_QSL
MVP
MVP

IF (peek(id)<>id,1, peek('counter2') + 1) AS counter2


or


IF (peek(id)<>id,1, peek(counter2) + 1) AS counter2

Not applicable
Author

Thank you,

I tried the solution unfortunatly it does not work hen I rename my column :

For example if I write this :

Temp2:

LOAD

id as toto,

field,

//IF (peek(id)<>id,1, peek(counter) + 1) AS counter2

IF (peek(id)<>id,1, peek('counter2') + 1) AS counter2,

peek(id) as previousvalue

RESIDENT Temp

ORDER BY id;

drop table Temp;

the result is :

Sans titre.png

because I add as toto

Thank you for your help

MK_QSL
MVP
MVP

Temp:

LOAD * INLINE [

id, field, counter

1, bla,0

1, bla,0

1, bla,0

2, bla,0

2, bla,0

2, bla,0

3, bla,0

3, bla,0

];

Temp2:

LOAD

id,

field,

IF (Previous(id)<>id,1, peek(counter2) + 1) AS counter2

RESIDENT Temp

ORDER BY id;

drop table Temp;

MK_QSL
MVP
MVP

one more easier way

Temp:

LOAD

  *,

  AutoNumber(RecNo(),id) as counter22

INLINE [

id, field, counter

1, bla,0

1, bla,0

1, bla,0

2, bla,0

2, bla,0

2, bla,0

3, bla,0

3, bla,0

];