Six Stars

How to get the sum of before rows in talend?

Hi team,

My source table is like

 

Capture.JPG,

I want to add the previous row sal to current like ,

Capture2.JPG

How can i achieve the above scenario 

Thanks in advance

 

Tags (1)
1 ACCEPTED SOLUTION

Accepted Solutions
Twelve Stars

Re: How to get the sum of before rows in talend?

If I understand you correctly, you can do this with a tMap and tMap variables. Take a look at the screen shot below. tmap1.png

I have set up a variable which carries out an accumulation calculation. It is created by clicking the green + at the center top of the tMap. I used a Double (class, not primitive type....essentially I just clicked the tick box next to the "Type" column) and added the following expression....

 

Var.sal_accumulator==null ? row1.sal : Var.sal_accumulator + row1.sal 

Since the tMap variables store values between rows, this make this calculation very easy.

Rilhia Solutions
3 REPLIES
Twelve Stars TRF
Twelve Stars

Re: How to get the sum of before rows in talend?

Hi,

 

You should have a look on tMemorizeRows component.


TRF
Twelve Stars

Re: How to get the sum of before rows in talend?

If I understand you correctly, you can do this with a tMap and tMap variables. Take a look at the screen shot below. tmap1.png

I have set up a variable which carries out an accumulation calculation. It is created by clicking the green + at the center top of the tMap. I used a Double (class, not primitive type....essentially I just clicked the tick box next to the "Type" column) and added the following expression....

 

Var.sal_accumulator==null ? row1.sal : Var.sal_accumulator + row1.sal 

Since the tMap variables store values between rows, this make this calculation very easy.

Rilhia Solutions
Twelve Stars TRF
Twelve Stars

Re: How to get the sum of before rows in talend?

In my opinion, @rhall_2_0's solution is better but a little bit more tricky than the solution I proposed using tMemorizeRows.


TRF