Qlik Community

Qlik Education Discussions

Discussion Board for collaboration related to Qlik Education.

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

Re: Peek function in load script

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;

4 Replies

Re: Peek function in load script

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


or


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

Not applicable

Re: Peek function in load script

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

Re: Peek function in load script

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;

Re: Peek function in load script

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

];

Community Browser