how to get cumulative sum

Post questions here relative to DataStage Enterprise/PX Edition for such areas as Parallel job design, Parallel datasets, BuildOps, Wrappers, etc.

Moderators: chulett, rschirm, roy

Post Reply
jhansi
Participant
Posts: 33
Joined: Sat May 26, 2012 4:56 am

how to get cumulative sum

Post 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
jhansi
nmadhu.etl
Participant
Posts: 3
Joined: Thu Apr 26, 2012 2:11 am
Location: Chennai

Re: how to get cumulative sum

Post 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.
Madhu
nmadhu.etl
Participant
Posts: 3
Joined: Thu Apr 26, 2012 2:11 am
Location: Chennai

Re: how to get cumulative sum

Post 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.
Madhu
jhansi
Participant
Posts: 33
Joined: Sat May 26, 2012 4:56 am

Re: how to get cumulative sum

Post by jhansi »

k its working.i did one small mistake
Last edited by jhansi on Thu Jun 14, 2012 7:17 am, edited 1 time in total.
jhansi
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post 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.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
bicap
Premium Member
Premium Member
Posts: 95
Joined: Mon May 03, 2010 10:22 pm
Location: India
Contact:

Post 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.
suman27
Participant
Posts: 33
Joined: Wed Jul 15, 2009 6:52 am
Location: London

Re: how to get cumulative sum

Post by suman27 »

No need of S3.
Also records need to be sorted by by ID :)
nmadhu.etl
Participant
Posts: 3
Joined: Thu Apr 26, 2012 2:11 am
Location: Chennai

Re: how to get cumulative sum

Post 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
Madhu
ntr
Participant
Posts: 110
Joined: Fri Dec 18, 2009 10:30 am
Location: pune

Re: how to get cumulative sum

Post 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
jhansi
Participant
Posts: 33
Joined: Sat May 26, 2012 4:56 am

Re: how to get cumulative sum

Post by jhansi »

sv1+sv2->sv2
or
sv1+sv3->sv2 both are working fine..
jhansi
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

So... resolved?
-craig

"You can never have too many knives" -- Logan Nine Fingers
jhansi
Participant
Posts: 33
Joined: Sat May 26, 2012 4:56 am

Post by jhansi »

without transformer can we do this scenario?
Last edited by jhansi on Sat Jun 16, 2012 10:08 pm, edited 1 time in total.
jhansi
jhansi
Participant
Posts: 33
Joined: Sat May 26, 2012 4:56 am

Re: how to get cumulative sum

Post 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
jhansi
BI-RMA
Premium Member
Premium Member
Posts: 463
Joined: Sun Nov 01, 2009 3:55 pm
Location: Hamburg

Post 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.
"It is not the lucky ones are grateful.
There are the grateful those are happy." Francis Bacon
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post 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.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
Post Reply