Skip to main content
Announcements
NEW: Seamless Public Data Sharing with Qlik's New Anonymous Access Capability: TELL ME MORE!
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Generate a key with previous or peek function

Hi Community,

I want a key, that will be generate from the first and second column.

it is important that "Col2" has the order 1,2,3,4,1,2,3,4.

The first four values are "Key_1" and the last four values from the "Col2" are "Key_2".

How can i generate the key with the previous or peek function?

has anyone an idea?

1 Solution

Accepted Solutions
Gysbert_Wassenaar

This should work if I understand what you want correctly:

LOAD *, 'Key_' & Counter as GeneratedKey;

LOAD *, if(previous(Col2)>Col2,rangesum(1,peek(Counter)),rangemax(1,peek(Counter))) as Counter;

LOAD * INLINE [

    Sample, Col2, GenerateKey , Value

    A, 1,Key_1,10

    A, 2 ,Key_1,20

    A, 3 ,Key_1,15

    A, 4 ,Key_1,30

    A, 1,Key_2,20

    A, 2,Key_2,30

    A, 3 ,Key_2,40

    A, 4 ,Key_2,50

];

Compare GeneratedKey with your field GenerateKey


talk is cheap, supply exceeds demand

View solution in original post

2 Replies
Gysbert_Wassenaar

This should work if I understand what you want correctly:

LOAD *, 'Key_' & Counter as GeneratedKey;

LOAD *, if(previous(Col2)>Col2,rangesum(1,peek(Counter)),rangemax(1,peek(Counter))) as Counter;

LOAD * INLINE [

    Sample, Col2, GenerateKey , Value

    A, 1,Key_1,10

    A, 2 ,Key_1,20

    A, 3 ,Key_1,15

    A, 4 ,Key_1,30

    A, 1,Key_2,20

    A, 2,Key_2,30

    A, 3 ,Key_2,40

    A, 4 ,Key_2,50

];

Compare GeneratedKey with your field GenerateKey


talk is cheap, supply exceeds demand
Not applicable
Author

Wow, thank you!