Skip to main content

Hi,

 

I appreciate this is an additional question on this topic, but I am struggling to get the Counter transformer to reset to 0 in my particular example.

I have a dataset along the following lines:

 

Site,Date,Event

Site1,20200101,0

Site1,20200102,0

Site1,20200103,1

Site1,20200104,0

Site2,20200101,0

Site2,20200102,4

Site2,20200103,0

Site2,20200104,0

 

I would like to set a Counter for each site to essentially calculate a value for "how many days since last event", i.e. the Count +1 for each 0 and resets when it encounters a non-0 value, resulting in:

Site,Date,Event, Days Since Last Event

Site1,20200101,0,0

Site1,20200102,0,1

Site1,20200103,1,0

Site1,20200104,0,1

Site2,20200101,0,0

Site2,20200102,4,0

Site2,20200103,0,1

Site2,20200104,0,2

 

I'm struggling to have the Counter reset to zero, perhaps I should be looking at an alternative approach, as per the advice from @takashi this Knowledge base article?

 

https://knowledge.safe.com/questions/5287/counter-by-group-but-reset-to-1-within-a-group.html

 

Many thanks in advance :)

Yes, in this case I'd be using the adjacent attribute functionality in an attributecreator rather than using the counter

 


If you set the Counter Name to counter_@Value(Site) you get a separate counter for each site.


Yes, in this case I'd be using the adjacent attribute functionality in an attributecreator rather than using the counter

 

Hi, thanks for the suggestion, this worked perfectly!


Reply