Addition of Rows in Datastage

A forum for discussing DataStage<sup>®</sup> basics. If you're not sure where your question goes, start here.

Moderators: chulett, rschirm, roy

Post Reply
dscon9128
Participant
Posts: 25
Joined: Fri Jun 13, 2008 9:11 am

Addition of Rows in Datastage

Post by dscon9128 »

Hi,

I would like to add records in datastage in such a way that I obtain the cumulative sum in the output column. So for example, if the

Input dataset

YEAR AMOUNT
2007 10
2008 20
2009 5
2010 15
2011 30


Output dataset should look like this:(CUMSUM is the output column)

YEAR AMOUNT CUMSUM
2007 10 10
2008 20 30
2009 5 35
2010 15 50
2011 30 80

If anyone can give me some suggestion as to how to go about achieving this, it would be great.

Thanks,

dscon9128
filename.txt
Participant
Posts: 27
Joined: Thu Mar 20, 2008 11:55 am

Re: Addition of Rows in Datastage

Post by filename.txt »

You can use Stage variable...

initial Stage var i =0

i=i+inrowlink

your outputlink=i
Thanks.

"Creativity is the ability to use your available resources to their fullest."
crouse
Charter Member
Charter Member
Posts: 204
Joined: Sun Oct 05, 2003 12:59 pm
Contact:

Post by crouse »

Check out hash partitioning and sorting, transforms and stage variables.

Hash partitioning gets the "like" data in the same partition, sort it in the right order, store the previous cumulative in a stage variable, add the stage variable to the new input row, output the row with the new cumulative.

Use stage variables to detect when to zero out the cumulative.
Craig Rouse
Griffin Resouces, Inc
www.griffinresources.com
crouse
Charter Member
Charter Member
Posts: 204
Joined: Sun Oct 05, 2003 12:59 pm
Contact:

Post by crouse »

Check out hash partitioning and sorting, transforms and stage variables.

Hash partitioning gets the "like" data in the same partition, sort it in the right order, store the previous cumulative in a stage variable, add the stage variable to the new input row, output the row with the new cumulative.

Use stage variables to detect when to zero out the cumulative.
Craig Rouse
Griffin Resouces, Inc
www.griffinresources.com
Post Reply