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

Announcements
Want to see what's currently in public preview? We've pulled it all together in one place. Check it out here
cancel
Showing results for 
Search instead for 
Did you mean: 
MRitter
Employee
Employee

Add a new key that increments for each ID value in data

Additional thought to my previous post.  Taking a different approach.

I want to add a new key to each row in my data.  But I want the value to start at 1 each time the ID changes in the data.

For example:

ID             Key

1                  1

2                  1

2                  2

2                  3

3                  1

I'm close. But just can't quite get it to work.

1 Solution

Accepted Solutions
Nicole-Smith
MVP
MVP

This should work for you:

Data:
LOAD * INLINE [
	ID
    1
    2
    2
    2
    3
];

Data_Final:
LOAD ID,
	 IF(Previous(ID) = ID, Peek(Key) + 1, 1) AS Key
RESIDENT Data
ORDER BY ID;

View solution in original post

1 Reply
Nicole-Smith
MVP
MVP

This should work for you:

Data:
LOAD * INLINE [
	ID
    1
    2
    2
    2
    3
];

Data_Final:
LOAD ID,
	 IF(Previous(ID) = ID, Peek(Key) + 1, 1) AS Key
RESIDENT Data
ORDER BY ID;