Automatic rownumber with reset on field

Hi,

I’m trying to implement a new column. This column needs to presentate the rownumber, but it needs te be reset when a other field is changing.

ID Name Row
1 Peter 1
2 Peter 2
3 Peter 3
4 Erik 1
5 Erik 2

Check the example above. The rownumber in the column Row is resetting when the value in the field Name is changing.

What i did:
I added a sequence and tried to reset this sequence in a reformat component:

$out.0.Counter = sequence(Activiteit_Telling).reset();

Where do i need to tell the sequence it have to reset on the name field?

Regards,

Daniël

Hi Daniel,

There are multiple ways to do this.

  • If the your data is sorted you can use a simple CTL transformation that will assign the sequence numbers to records - you do not even need to use Clover sequences as this could be simply handled by simple integer variables.

  • If you don’t have the data sorted, you might want to use another approach - Clover lookup tables might help you get this done. In the lookup table, you would just keep the keys with their latest sequences. If you need to keep the sequences between the graph executions, you might want to use persistent lookup tables.

In the attached graph, there are example of both options prepared for your convenience.

StringSeq.grf