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

Announcements
Join us in Bucharest on Sept 18th for Qlik's AI Reality Tour! Register Now
cancel
Showing results for 
Search instead for 
Did you mean: 
devan9876
Creator
Creator

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

1 Solution

Accepted Solutions
sunny_talwar

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

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

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
Creator
Author

That seems to work.

Thanks!