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

Announcements
Qlik GA: Multivariate Time Series in Qlik Predict: Get Details
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Funtion Optimization

hello everyone,

i have function optimization problem, i want to count the distinct "%SessionID" with the help of my script.

i used this .....AutoNumber(RecNo(), %SessionId) as NewID ..// this is working perfectly ok...like its returning me the NewID field with values 1,2,3,4... but this autonumber function is slow i want to use some thing like this

if (peek( '%SessionID')= %SessionID , (%SessionID+1),1)....// its not working its returning me 1,1,1,1,1...in all fields with same %SessionID. but i need the outcome like 1,2,3,4....

Any help on this?

Regards,

Salman

1 Solution

Accepted Solutions
d_pranskus
Partner - Creator III
Partner - Creator III

Try this example

t:

LOAD * INLINE [

          %session

          1

          1

          1

          1

          2

          2

          2

          2

          3

          3

          4

          4

          4

          4

];

t1:

LOAD

          %session,

          IF(PEEK('%session') = %session, PEEK('newid') + 1, 1) AS newid

RESIDENT t;

DROP TABLE t;

And you must have your source table sorted by %session.

Darius

View solution in original post

6 Replies
d_pranskus
Partner - Creator III
Partner - Creator III

Hi

Try this

if (peek( '%SessionID')= %SessionID , (peek('%SessionID')+1),1)

Darius


CELAMBARASAN
Partner - Champion
Partner - Champion

Hi,

     Try with previous() or peek() like this

     if (Previous( [%SessionID]) = [%SessionID] , (NewID+1),1) as NewID

     if (peek( '%SessionID')= [%SessionID] , (NewID+1),1) as NewID

Celambarasan

Not applicable
Author

thanks Darius, i have tried this but returning the same values in the column..1,1,1,1,1...

Not applicable
Author

thanks Celambarasan, but getting the same result 1,1,1,1,1...

I have to use Autonumber for numbering like 1,2,3,4 ....  for the same %SessionID ?

regards,

salman

d_pranskus
Partner - Creator III
Partner - Creator III

Try this example

t:

LOAD * INLINE [

          %session

          1

          1

          1

          1

          2

          2

          2

          2

          3

          3

          4

          4

          4

          4

];

t1:

LOAD

          %session,

          IF(PEEK('%session') = %session, PEEK('newid') + 1, 1) AS newid

RESIDENT t;

DROP TABLE t;

And you must have your source table sorted by %session.

Darius

Not applicable
Author

Perfect Darius,Thanks:)