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

Number ordered sequence of group during load

Hi,

I have the following table.

UserID, Date, Item

1, 01.01.2017, 5     -> 1

1, 01.03.2017, 5     -> 3

1, 01.02.2017, 5     -> 2

2, 01.02.2017, 5     -> 1

2, 01.03.2017, 5     -> 2

I want to create a row number for each group (UserID), but within the group the rows need to be sorted by Date.

I need to do this in the load script, as I have more than 5Mio UserIDs.

Can someone give me a hint? I tried the following, and it worked for a small test set, but for the real dataset calculation crashes after hours:

Load *,

       AutoNumber(RecNo(),UserID) AS Sequence

Resident Fact

Order By UserID,Date;

Thanks!

1 Solution

Accepted Solutions
sunny_talwar

Try using Peek/Previous

LOAD *,

       If(UserID = Previous(UserID), RangeSum(Peek('Sequence'), 1), 1) as Sequence

Resident Fact

Order By UserID, Date;

View solution in original post

4 Replies
udaya_kumar
Specialist
Specialist

Can you try Autonumber(UserID, Date) as sequence

nigel987
Creator II
Creator II
Author

This does not deliver correct results

sunny_talwar

Try using Peek/Previous

LOAD *,

       If(UserID = Previous(UserID), RangeSum(Peek('Sequence'), 1), 1) as Sequence

Resident Fact

Order By UserID, Date;

vinieme12
Champion III
Champion III

Try below

Autonumber(UserID&Date, UserID)  as instanceID

Vineeth Pujari
If a post helps to resolve your issue, please accept it as a Solution.