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: 
devan9876
Creator II
Creator II

How to reset counter at each unique value in script?

Hypothetical Source Data:

Dog

Dog

Dog

Dog

Cat

Cat

Chicken

Chicken

Bird

Desired Output:

Dog|1

Dog|2

Dog|3

Dog|4

Cat|1

Cat|2

Cat|3

Chicken|1

Chicken|2

Bird|1

Labels (1)
1 Solution

Accepted Solutions
sunny_talwar
MVP
MVP

2 Ways

1) Using Peek/Previous

Fact:

LOAD Field

FROM ...;

FinalFact:

LOAD Field,

     If(Field = Previous(Field), RangeSum(Peek('Counter'), 1), 1) as Counter

Resident Fact

Order By Field;

2) Using AutoNumber

Fact:

LOAD Field

FROM ...;

FinalFact:

LOAD Field,

     AutoNumber(RecNo(), Field) as Counter

Resident Fact

Order By Field;

View solution in original post

3 Replies
Anil_Babu_Samineni
MVP
MVP

May be this?

LOAD FieldName & '|' & AutoNumber(RecNo(), FieldName) as FieldName Inline [

FieldName

Dog

Dog

Dog

Dog

Cat

Cat

Chicken

Chicken

Bird

];

Best Anil, When applicable please mark the correct/appropriate replies as "solution" (you can mark up to 3 "solutions". Please LIKE threads if the provided solution is helpful
sunny_talwar
MVP
MVP

2 Ways

1) Using Peek/Previous

Fact:

LOAD Field

FROM ...;

FinalFact:

LOAD Field,

     If(Field = Previous(Field), RangeSum(Peek('Counter'), 1), 1) as Counter

Resident Fact

Order By Field;

2) Using AutoNumber

Fact:

LOAD Field

FROM ...;

FinalFact:

LOAD Field,

     AutoNumber(RecNo(), Field) as Counter

Resident Fact

Order By Field;

devan9876
Creator II
Creator II
Author

That seems to work.

Thanks!