I want to develop a logic in which I check the column value of current row and earlier row. If its different, I want to increment the counter by 1.
e.g. Row 1.Name = A
Row2.Name = A
Row3.Name = B
Row4.Name = C
So here Name is changed from A to B to C, there I will be incrementing the counter by 1. If its same Name no counter increment.
Any suggestion on how to remember the column value of earlier row and compare it to current row.
Thanks.
Current Row and Previous Row
Moderators: chulett, rschirm, roy
Stage variables are processed in order, you can therefore store values from the previous record in them
svPreviousValue = svCurrentValue
svCurrentValue = input.field
svValueHasChanged = If svCurrentValue = svPreviousValue Then 0 Else 1
svCounter = If svValueHasChanged Then svCounter + 1 Else svCounter
Regards,
Nick.
Nick.
-
- Participant
- Posts: 612
- Joined: Thu May 03, 2007 4:59 am
- Location: Melbourne
In case you want to do this for record groups:
Use a sort stage. Sort records based on your key. Add SORT stage property Create Key Change Column. This property will add a column to your output link. The value of this column is 1 for the first record in the sort record group else the value is 0. In transformer use stage variables as stated in the above post. When a new record group comes the first record will be coming with key change column as 1, that time reset the svCounter to 1.
Use a sort stage. Sort records based on your key. Add SORT stage property Create Key Change Column. This property will add a column to your output link. The value of this column is 1 for the first record in the sort record group else the value is 0. In transformer use stage variables as stated in the above post. When a new record group comes the first record will be coming with key change column as 1, that time reset the svCounter to 1.
Joshy George
<a href="http://www.linkedin.com/in/joshygeorge1" ><img src="http://www.linkedin.com/img/webpromo/bt ... _80x15.gif" width="80" height="15" border="0"></a>
<a href="http://www.linkedin.com/in/joshygeorge1" ><img src="http://www.linkedin.com/img/webpromo/bt ... _80x15.gif" width="80" height="15" border="0"></a>
-
- Participant
- Posts: 3593
- Joined: Thu Jan 23, 2003 5:25 pm
- Location: Australia, Melbourne
- Contact:
Since this is a parallel job make sure you have sorted and partitioned by your Name field so that matching rows are adjacent to each other and on the same node in the Transformer.
Certus Solutions
Blog: Tooling Around in the InfoSphere
Twitter: @vmcburney
LinkedIn:Vincent McBurney LinkedIn
Blog: Tooling Around in the InfoSphere
Twitter: @vmcburney
LinkedIn:Vincent McBurney LinkedIn
-
- Participant
- Posts: 54607
- Joined: Wed Oct 23, 2002 10:52 pm
- Location: Sydney, Australia
- Contact:
I have a similar kind of requirement so I thought I'd ask here itself. Which stage variable should we give in the derivation for the Output Columns? That is, should the stage variable prefixed 'prev' be used or the one with 'curr' be used?
When I use 'prev' the first row is displayed with empty rows and when I use 'curr' the values are not displayed as expected...if it is inappropriate to continue in this topic, let me know..I will start a new topic with complete details...
When I use 'prev' the first row is displayed with empty rows and when I use 'curr' the values are not displayed as expected...if it is inappropriate to continue in this topic, let me know..I will start a new topic with complete details...
Joel Satire