Skip to main content
Announcements
Qlik Connect 2024! Seize endless possibilities! LEARN MORE
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

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

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;