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

Announcements
Qlik Open Lakehouse is Now Generally Available! Discover the key highlights and partner resources here.
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

repeating counter for common fields

Hi,

This should be easy... table

Suppose I have the following:

DayShift Id
4-10-201012
4-10-201012
4-10-201014
4-10-201014
5-10-201015
5-10-201015
5-10-201015
5-10-201015
5-10-201015
5-10-201015


Now, I would like to have a running index on both fields. Counter that will resets itself as soon as a new subset appears.

This is the desired outcome:

DayShift Idindex
4-10-2010121
4-10-2010122
4-10-2010141
4-10-2010142
5-10-2010151
5-10-2010152
5-10-2010153
5-10-2010154
5-10-2010155
5-10-2010156


I've tried autonumber, but unfortunatly the counter does not reset itself. Is there a simple way i can tuckle this?

Dror

1 Solution

Accepted Solutions
Not applicable
Author

Hi,

Syed is right, the load sentence would be as following:


Data:
LOAD
Days,
[Shift Id],
if(Days = previous(Days) and [Shift Id] = previous([Shift Id]), peek('Index',-1) + 1,1) as Index
INLINE [
Days, Shift Id
4-10-2010, 12
4-10-2010, 12
4-10-2010, 14
4-10-2010, 14
5-10-2010, 15
5-10-2010, 15
5-10-2010, 15
5-10-2010, 15
5-10-2010, 15
5-10-2010, 15
];


Regards.

View solution in original post

3 Replies
syed_muzammil
Partner - Creator II
Partner - Creator II

Hi,

You can try ordering the table on load on Day and Shift ID and user the peek and previous functions to increment or reset the index column.

Eg. If Previous(Shiftid)= Shiftid then Peek(Index,-1)+1 else 1.

Rgards,

Syed.

Not applicable
Author

Hi,

Syed is right, the load sentence would be as following:


Data:
LOAD
Days,
[Shift Id],
if(Days = previous(Days) and [Shift Id] = previous([Shift Id]), peek('Index',-1) + 1,1) as Index
INLINE [
Days, Shift Id
4-10-2010, 12
4-10-2010, 12
4-10-2010, 14
4-10-2010, 14
5-10-2010, 15
5-10-2010, 15
5-10-2010, 15
5-10-2010, 15
5-10-2010, 15
5-10-2010, 15
];


Regards.

Not applicable
Author

Thanks it works!