Skip to main content
Announcements
NEW: Seamless Public Data Sharing with Qlik's New Anonymous Access Capability: TELL ME MORE!
cancel
Showing results for 
Search instead for 
Did you mean: 
devans_1
Creator
Creator

Setting a counter flag in a script

Does anyone have an idea of how to create a 'counter flag' when runnign a script ? Suppose I have fields (or a combination of fields that make up the key)

AAABBBCCC

AAABBBCCC

AAABBBDDD

AAABBBDDD

AAABBBEEE

AAABBBCCC

I want to be able to set a flag so that I get

field                 Counter

AAABBBCCC 1

AAABBBCCC 1

AAABBBDDD 2

AAABBBDDD 2

AAABBBDDD 2

AAABBBEEE 3

AAABBBCCC 4.

AUTONUMBER takes me partially there but this would duplicate a counter of '1' for the final AAABBBCCC. I need to have a new number for this field because of the rest of the data that is held on this field (it's complicated but it holds all sorts of numbers which I'm doing calculations on so I can't sort on any other fields - however, assuming the data is correctly ordered above, any help would be appreciated).

1 Solution

Accepted Solutions
swuehl
MVP
MVP

Maybe like this:

LOAD Field,

if(recno()=1,1,if(peek(Field) = Field, peek(Flag),peek(Flag)+1)) as Flag

INLINE [

Field

AAABBBCCC

AAABBBCCC

AAABBBDDD

AAABBBDDD

AAABBBEEE

AAABBBCCC

];

View solution in original post

2 Replies
swuehl
MVP
MVP

Maybe like this:

LOAD Field,

if(recno()=1,1,if(peek(Field) = Field, peek(Flag),peek(Flag)+1)) as Flag

INLINE [

Field

AAABBBCCC

AAABBBCCC

AAABBBDDD

AAABBBDDD

AAABBBEEE

AAABBBCCC

];

devans_1
Creator
Creator
Author

Thanks for this. It is exactly what I needed. Works perfectly