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

Announcements
Save $650 on Qlik Connect, Dec 1 - 7, our lowest price of the year. Register with code CYBERWEEK: Register
cancel
Showing results for 
Search instead for 
Did you mean: 
EV89
Contributor III
Contributor III

RowNumber for group of value

Hi everyone,

 

i have this situation

 

Key        

A

A

B

C

D

D

 

I want compute the rowId, mantaining the same value for the same key. Sample of expected output value

 

Key    RowId        

A       1

A       1

B       2

C       3

D       4

D       4

 

Any idea?

 

thank you

Labels (2)
1 Solution

Accepted Solutions
Anonymous
Not applicable

You can do this with a tJavaFlex component. The code you will need looks like below....

Start Code

// start part of your Java code
int rowNum = 0;

Main Code

// here is the main part of the component,
// a piece of code executed in the row
// loop
String value = row1.Key;

if(globalMap.get(value)==null){
	rowNum = rowNum+1;
	globalMap.put(value, rowNum);
}

row2.RowId = ((Integer)globalMap.get(value)).intValue();

 

What the above is doing is keeping a track of the RowId count using the "rowNum" created in the Start Code section. Then, it is creating a globalMap key/value pair for every "Key" in your data. Once the "Key" is created once, it is assigned the current "rowNum" which is appended by 1. Every time that "Key" is seen again, it is assigned the value stored in the globalMap.

View solution in original post

4 Replies
Anonymous
Not applicable

You can do this with a tJavaFlex component. The code you will need looks like below....

Start Code

// start part of your Java code
int rowNum = 0;

Main Code

// here is the main part of the component,
// a piece of code executed in the row
// loop
String value = row1.Key;

if(globalMap.get(value)==null){
	rowNum = rowNum+1;
	globalMap.put(value, rowNum);
}

row2.RowId = ((Integer)globalMap.get(value)).intValue();

 

What the above is doing is keeping a track of the RowId count using the "rowNum" created in the Start Code section. Then, it is creating a globalMap key/value pair for every "Key" in your data. Once the "Key" is created once, it is assigned the current "rowNum" which is appended by 1. Every time that "Key" is seen again, it is assigned the value stored in the globalMap.

Anonymous
Not applicable

I should point out that I used the globalMap because it was easy. It might be better to create your own HashMap object to store these values in. This will protect against you accidentally affecting other key/value pairs that the globalMap might hold.

EV89
Contributor III
Contributor III
Author

Anonymous
Not applicable

I assume that you posted this to show how you got you job to work?