Page 1 of 1
how to get cumulative sum
Posted: Thu Jun 14, 2012 2:25 am
by jhansi
source
id,sal
10,1000
20,2000
30,3000
40,5000
target:
id,sal,cum_sum
10,1000,1000
20,2000,3000
30,3000,6000
40,5000,11000
Re: how to get cumulative sum
Posted: Thu Jun 14, 2012 3:26 am
by nmadhu.etl
hi,
this will get by using transformer stage.
here u can take three stage variables like sv1,sv2,and sv3.
Assign default values as 0.
sal -> sv1
sv1+sv2 -> sv2 this one drag to cum_column
sv2 -> sv3
i think this is help u.
Re: how to get cumulative sum
Posted: Thu Jun 14, 2012 3:27 am
by nmadhu.etl
hi,
this will get by using transformer stage.
here u can take three stage variables like sv1,sv2,and sv3.
Assign default values as 0.
sal -> sv1
sv1+sv2 -> sv2 this one drag to cum_column
sv2 -> sv3
i think this is help u.
Re: how to get cumulative sum
Posted: Thu Jun 14, 2012 3:30 am
by jhansi
k its working.i did one small mistake
Posted: Thu Jun 14, 2012 3:50 am
by ray.wurlod
Then you're not doing it right. Show us exactly what stage variables you are using, how each is initialized and how each is derived as each row is processed.
Posted: Thu Jun 14, 2012 4:03 am
by bicap
Take two stage variable S1 and S2.. Initialise both to zero.
Use below logic.
SAL+S1 => S2 ( Map S2 to cumu_column)
S2 => S1
And make sure you execute transformer in sequential mode.
Re: how to get cumulative sum
Posted: Thu Jun 14, 2012 4:08 am
by suman27
No need of S3.
Also records need to be sorted by by ID
![Smile :)](./images/smilies/icon_smile.gif)
Re: how to get cumulative sum
Posted: Thu Jun 14, 2012 4:30 am
by nmadhu.etl
sorry actually i want to said this one
sal -> sv1
sv1+sv3 -> sv2 this one drag to cum_column
sv2 -> sv3
without sv3 also working previous one
Re: how to get cumulative sum
Posted: Thu Jun 14, 2012 4:40 am
by ntr
if st1 is null then SAL else st1+SAL--------st1
(OR)
if @inrownum=1 then SAL else st1+SAL--------st1
map st1 to sumcolum
make sure the data should be sorted based on SAL
Re: how to get cumulative sum
Posted: Thu Jun 14, 2012 7:31 am
by jhansi
sv1+sv2->sv2
or
sv1+sv3->sv2 both are working fine..
Posted: Thu Jun 14, 2012 7:39 am
by chulett
So... resolved?
Posted: Thu Jun 14, 2012 7:46 am
by jhansi
without transformer can we do this scenario?
Re: how to get cumulative sum
Posted: Thu Jun 14, 2012 8:51 am
by jhansi
both are also working good.
ntr wrote:if st1 is null then SAL else st1+SAL--------st1
(OR)
if @inrownum=1 then SAL else st1+SAL--------st1
map st1 to sumcolum
make sure the data should be sorted based on SAL
Posted: Thu Jun 14, 2012 9:04 am
by BI-RMA
I would not say it is impossible, but all solutions without a Transformer are beyond Your experience level. Leave it at that.
Posted: Thu Jun 14, 2012 4:28 pm
by ray.wurlod
jhansi wrote:without transformer can we do this scenario?
Is this an interview question?
Why do you want to do it without a Transformer stage?
It used to be the case that the Transformer stage was inefficient but they did a lot of work to it (version 8.1.x ?) and that advice is no longer correct.