Six Stars

## How to get the sum of before rows in talend?

Hi team,

My source table is like

,

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

How can i achieve the above scenario

Tags (1)

Accepted Solutions
Sixteen 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.

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.

All Replies
Forteen Stars

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

Hi,

You should have a look on tMemorizeRows component.

TRF
Sixteen 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.

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.

Forteen 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