Qlik Community

New to Qlik Sense

Discussion board where members can get started with Qlik Sense.

Announcements
BI & Data Trends 2021. Discover the top 10 trends emerging in today. Join us on Dec. 8th REGISTER
cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
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
Highlighted

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
Highlighted

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