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

Announcements
Posting on Qlik Community is temporarily paused for some users. Thank you for patience and we'll update you soon!
cancel
Showing results for 
Search instead for 
Did you mean: 
semgem12
Contributor III
Contributor III

Unique row counter

Hello all

I have a data set as follows

Order No
DateDept
1000001/05/16A
1000101/05/16B
1000201/05/16B
1000301/05/16B
1000401/05/16C
1000501/05/16C
1000601/05/16D
1000702/05/16B

The data is being loaded and sorted by date and within date by dept. I would like to somehow assign a row number during the load script to each order line so that for each dept within a date, the row number starts at 1 and increments until the next dept at which point it starts at 1 again, i.e.

OrderDateDeptRow Number
1000001/05/16A1
1000101/05/16

B

1
1000201/05/16B2
1000301/05/16B3
1000401/05/16C1
1000501/05/16C2
1000601/05/16D1
1000702/05/16B1

Would be grateful if someone could point me in the right direction please. Thanks in advance.

Labels (1)
1 Solution

Accepted Solutions
antoniotiman
Master III
Master III

Hi,

try like this

LOAD [Order No],
Date,
Dept,
If(Peek(Dept)=Dept and Peek(Date)=Date,Peek(RowNo)+1,1) as RowNo
FROM
"https://community.qlik.com/message/1126571"
(html, codepage is 1252, embedded labels, table is
@1);

Regards,

Antonio

View solution in original post

5 Replies
antoniotiman
Master III
Master III

Hi,

try like this

LOAD [Order No],
Date,
Dept,
If(Peek(Dept)=Dept and Peek(Date)=Date,Peek(RowNo)+1,1) as RowNo
FROM
"https://community.qlik.com/message/1126571"
(html, codepage is 1252, embedded labels, table is
@1);

Regards,

Antonio

semgem12
Contributor III
Contributor III
Author

Wow! Thank you so much, that has worked perfectly. It has generated the row numbers exactly as I needed them. Thank you for replying to my question so quickly.

sunny_talwar
MVP
MVP

You can also try this:

Table:

LOAD [Order No],

    Date,

    Dept,

    AutoNumber(RowNo(), Date&Dept) as [Row Number]

FROM

[https://community.qlik.com/thread/233353]

(html, codepage is 1252, embedded labels, table is @1);


Capture.PNG

semgem12
Contributor III
Contributor III
Author

Thank you Sunny, that works perfectly too. Great to have two different solutions.

Digvijay_Singh
MVP
MVP

try this -

Temp:

LOAD [Order No],

     Date,

     Dept

FROM

[https://community.qlik.com/thread/233353]

(html, codepage is 1252, embedded labels, table is @1);

Final:

Load *,

  If(Previous(Dept)=Dept and Previous(Date)=Date,Peek(RowNo)+1,1) as RowNo

  

resident Temp

Order By Date,Dept;

drop table Temp;