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

Announcements
Qlik Open Lakehouse is Now Generally Available! Discover the key highlights and partner resources here.
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Number rows grouped by user_id

Hi,

I´m facing a Problem:

Let´s say I have a Table like:

id
user_id
date
112015-01-01
222015-01-01
312015-01-02
412015-01-03
522015-01-03
632015-01-01

What i want to achieve:

I want to number the rows grouped by the field "user_id". the row with the lowest date should be "1", the row with the second lowest date should be "2", and so on.

Result should be like:

iduser_iddateNumber
112015-01-011
222015-01-011
312015-01-022
412015-01-033
522015-01-032
632015-01-011

Can somebody please help me. I couldn´t find any solution.

Thank you

1 Solution

Accepted Solutions
Gysbert_Wassenaar
Partner - Champion III
Partner - Champion III

Like this:

MyTable:

LOAD

     id,

     user_id,

     date,

     autonumber(RecNo(),user_id) as Number

FROM ...mysource...;


talk is cheap, supply exceeds demand

View solution in original post

3 Replies
Gysbert_Wassenaar
Partner - Champion III
Partner - Champion III

Like this:

MyTable:

LOAD

     id,

     user_id,

     date,

     autonumber(RecNo(),user_id) as Number

FROM ...mysource...;


talk is cheap, supply exceeds demand
pokassov
Specialist
Specialist

Hello!

Can you change your script to achieve your goal?

If the answer is 'Yes' then:

t2:

noconcatenate

load id, user_id, date,

if(previous(user_id)<>user_id,1,peek('number_user')+1) as number_user

resident your_table

order by user_id, date

left join (your_table)

load id, nu,ber_user

resident t2;

drop table t2;

Not applicable
Author

wow, thank you!