Skip to main content
Solved

Resetting Counter to zero within a group

  • May 26, 2020
  • 3 replies
  • 73 views

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

 

This post is closed to further activity.
It may be an old question, an answered question, an implemented idea, or a notification-only post.
Please check post dates before relying on any information in a question or answer.
For follow-up or related questions, please post a new question or idea.
If there is a genuine update to be made, please contact us and request that the post is reopened.

3 replies

ebygomm
Influencer
Forum|alt.badge.img+44
  • Influencer
  • 3427 replies
  • 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
  • 132 replies
  • May 26, 2020

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


  • Author
  • 2 replies
  • May 26, 2020

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!