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

Announcements
Discover how organizations are unlocking new revenue streams: Watch here
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

Use previous row as current row calculation

hi all,
i just wonder how talend can get previous row value to be used in current row mathematical calculation. Example:

A    X1          Y1 = (Y0-X1)*A
----------------------------------------
--   --                   0
1    5            (0 - 5)*1 = -5
2    3            (-5-3)*2 = -16
3    6            (-16-6)*3 = -66
4    2            (-66-2)*4 = -272


How do i can calculate formula Y1 as above.

i really appreciate your help.


Thanks.

Labels (2)
7 Replies
Anonymous
Not applicable
Author

Hi all,
Plz help me 0683p000009MPcz.png
Anonymous
Not applicable
Author

Hi
You can store the calculation result to a global variable on tJavaRow for used later. eg:
...tMap--main--tJavaRow

Doing the calculation on tMap:
(Integer)globalMap.get("result")==null?(0-row1.X1)*row1.A: ((Integer)globalMap.get("result")--row1.X1)*row1.A

on tJavaRow:
globalMap.put("result", input_row.Y1);
Anonymous
Not applicable
Author

Hi shong,

I have tried the solution above, but its still not working.
My condition is (Double)globalMap.get("result") == null ? 100.0 : (Double)globalMap.get("result") + 1  
But the result return as picture below.
0683p000009MH5O.png
Anonymous
Not applicable
Author

I see you use another expression to calculate the data, what's your input data? What are your expected result? 
Anonymous
Not applicable
Author

I can see an example here .Let us know if it helps :

https://talendtutorials.wordpress.com/
Anonymous
Not applicable
Author

Example:

Ty  Survival_Ft
---  -------------
0       100
1       100 + 1 = 101
2       101 + 1 = 102
3       102 + 1 = 103
4       103 + 1 = 104

I want to use the previous row answer to calculate for the next row.
Thanks.
Anonymous
Not applicable
Author

Take a look at tMemorizeRows component, this component can fit your need.