Cumulative Totals using Stage Variables

Post questions here relative to DataStage Server Edition for such areas as Server job design, DS Basic, Routines, Job Sequences, etc.

Moderators: chulett, rschirm, roy

Post Reply
Dsnew
Participant
Posts: 90
Joined: Tue Apr 19, 2005 2:08 pm

Cumulative Totals using Stage Variables

Post by Dsnew »

Hi,


I am looking to get a column F2 having cumulative totals from column F1
Also I need it to reset for each year.
I am guessing stage Variables is the way to, but no clue as to how to go about it.
Can someone help me out with.
Please let me know if my requirement is not clear.
Thanks in advance.


Example

YEAR,F1,F2
--------------
2005,20,20
2005,10,30
2005,20,50
2005,10,60
2005,10,70
2005,20,90

2006,10,10
2006,30,40
2006,10,50
2006,20,70
2006,10,80
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

Create two stage variables to detect change in year, and one to accumulate the running total. Initialize all to zero. Ensure that your data are sorted by year for this to make any sense.

Code: Select all

svYearChange    In.Year <> svPrevYear
svPrevYear      In.Year
svRunningTotal  If svYearChange Then In.F1 Else In.F1 + svRunningTotal
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
laknar
Participant
Posts: 162
Joined: Thu Apr 26, 2007 5:59 am
Location: Chennai

Post by laknar »

Sort The Year by using sort stage. And in Transformer Stage define

Svyear(Initial Variable '0')
--------------------

Code: Select all

YearColumn<>Svyear Then 1 Else SvYear+1 



SvF1(Initial Variable '0')
--------------------

Code: Select all

Svyear=1 Then F1 Else F1 + SvF1
i haven't tested the code.
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

For non-premium readers, I would like to point out that laknar's post is quite unlike mine. I have tested mine, and it works.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
Dsnew
Participant
Posts: 90
Joined: Tue Apr 19, 2005 2:08 pm

Post by Dsnew »

Ray,

Thank you very much, It solved my problem.
You are the man!
kiran259
Participant
Posts: 48
Joined: Thu Aug 16, 2007 11:17 pm
Location: United States
Contact:

Post by kiran259 »

Could you post your solution? :)

Thanks
Kiran
Kiran Vaduguri

As soon as the fear approaches near, attack and destroy it.
Post Reply