Page 1 of 1

Addition of Rows in Datastage

Posted: Fri Jul 11, 2008 3:07 pm
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

Re: Addition of Rows in Datastage

Posted: Fri Jul 11, 2008 3:18 pm
by filename.txt
You can use Stage variable...

initial Stage var i =0

i=i+inrowlink

your outputlink=i

Posted: Fri Jul 11, 2008 3:27 pm
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.

Posted: Fri Jul 11, 2008 3:28 pm
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.