Skip to main content
Announcements
New: No-code data prep in Qlik Cloud Analytics™ TAKE A TOUR
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

How to get next record's value while processing an input ?

 
Labels (3)
18 Replies
Anonymous
Not applicable
Author

Can you show some screenshots of your job configuration, since I do not understand what you are trying to do. Are you reading in an MD5 String? I'll need a bit more info

Anonymous
Not applicable
Author

In a similar situation:

Input

MASTER_CODECOMM
XLMAC-123-1
AAAAA-111-1
BBBBC-123-1
BBBBD-123-1
CCCCC-333-3
XLMS-AC-553-2
XLMS-AD-323-1
XLMS-AE-311-3

 

Desired output

MASTER_CODECOMM
XLMAC-123-1
AAAAA-111-1
BBBBC-123-1
 D-123-1
CCCCC-333-3
XLMS-AC-553-2
 D-323-1
 E-311-3

 

I'm trying to do it using tJavaRow but no luck, this is the code I'm using:

row2.MASTER_CODE.equals(row1.MASTER_CODE);
row2.COMM.equals(row1.COMM);
if((String)globalMap.get("PrevRow").equals(row1.MASTER_CODE))
 row2.MASTER_CODE.equals("");
else
 row2.MASTER_CODE.equals(row1.MASTER_CODE);
globalMap.set("PrevRow", row1.MASTER_CODE);
Anonymous
Not applicable
Author

Your Java is incorrect. The "equals" method doesn't assign a value, it checks to see if two values are equal. This should work....

 

if(globalMap.get("PrevRow")!=null&&((String)globalMap.get("PrevRow")).equals(row1.MASTER_CODE)){
      row2.MASTER_CODE = "";
}else{
     globalMap.put("PrevRow",row1.MASTER_CODE);
     row2.MASTER_CODE = ((String)globalMap.get("PrevRow"));
     row2.COMM = row1.COMM;
}   
Anonymous
Not applicable
Author

Thanks for your reply!
This almost solves it. The remaining issue is that the COMM field is not showing the correct values:

MASTER_CODE COMM Should be
XLMA C-123-1  
AAAA A-111-1  
BBBB C-123-1  
  C-123-1 D-123-1
CCCC C-333-3  
XLMS-A C-553-2  
  C-553-2 D-323-1
  C-553-2 E-311-3

 

 

TRF
Champion II
Champion II

What about this one?

if((String)globalMap.get("PrevRow") != null &&
((String)globalMap.get("PrevRow")).equals(input_row.MASTER_CODE)){
output_row.MASTER_CODE = "";
}else{
globalMap.put("PrevRow", input_row.MASTER_CODE);
output_row.MASTER_CODE = input_row.MASTER_CODE;
}
output_row.COMM = input_row.COMM;
Anonymous
Not applicable
Author

Excellent, this worked! Simply moving the COMM field out of the IF statement solves it.

Thanks for your help!

Anonymous
Not applicable
Author

Sorry, I wrote that straight to the forum without testing it. I meant the COMM field to be outside of the IF hence it was only included once.

Not applicable

i also need to get next record's value for process. i didn't find the solution in forum. kindly share the solution u got

Anonymous
Not applicable
Author

How do you decide the next row , it should be based on a column. for example , for a customer-purchase information file i would consider that the next row is based upon his purchase date ie , for a customer A (considering two purchases for him) the next row will be the row having the maximum date and the current row will be the row having minimum date. So the next and the current rows are always dependent upon a column (date,sequential number,rank etc.)

Hence , for the above example ,sorting descending upon the purchase-date column on every customer group , we can get the next purchase date for the customer row with current purchase date by fetching the previous date value using tmemorize or a variable storing the previous value.

In Java , it is always a top down approach and we cant get the next iteration's value sitting on the current iteration . The above solution would be a workaround to achieve what you want.