Skip to main content
Solved

Resetting Counter to zero within a group


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 :)

Best answer by ebygomm

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

 

View original
Did this help you find an answer to your question?

3 replies

ebygomm
Influencer
Forum|alt.badge.img+33
  • Influencer
  • Best Answer
  • May 26, 2020

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

 


gazza
Contributor
Forum|alt.badge.img+6
  • Contributor
  • May 26, 2020

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


  • Author
  • May 26, 2020
ebygomm wrote:

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!


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings