Skip to main content
Solved

Count if event happened consecutively based on other variable.


alejacd
Contributor
Forum|alt.badge.img+1

Hello, 

I have these data

Area Category Date
Medium  202301
A High 202305
B Medium High 202306
B Medium High 202305
B Medium High 202304
B Medium High 202303
B Medium High 202302
B Medium High 202301
C Low 202306
C Low 202305
C Medium 202304
C Low 202303
D High 202306
D Low 202305
D Low 202304
D Low 202303
E High 202306
E High 202305
E High 202304
E Medium High 202303
E Medium High 202302
E Medium High 202301

I want to count the categories that occurred 3 or more times consecutively per area. 

So something like these

 

Area Category Count Same category consecutively >3
  0
B Medium High 6
C   0
D Low 3
E High 3
E Medium High 3

 

I am not sure how to do it in FME. 

Thank you!

Best answer by geomancer

Something like this?

First the workspace adds all missing Area + Date combinations.

Then the consecutive occurences are counted. The AttributeManager uses Adjacent Feature Attributes, the Statistics Calculator gets the maximum values.

Some areas are missing from the results, so they are added in the last step.

 

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

9 replies

geomancer
Evangelist
Forum|alt.badge.img+47
  • Evangelist
  • April 23, 2024

Additional test data:

Area Category Date
F Medium High 202306
F Medium High 202305
F Medium High 202302
F Medium High 202301

Rows 202303 and 202304 are missing, so would this be considered as 3 or more times consecutive occurences?


alejacd
Contributor
Forum|alt.badge.img+1
  • Author
  • Contributor
  • April 23, 2024

If the date is not present, it means that no data was registered. So it won’t be considered as consecutive. 


geomancer
Evangelist
Forum|alt.badge.img+47
  • Evangelist
  • April 23, 2024

Thanks for your reply. I suspected as much, but there was no example data for this situation.

I'll take a look.


geomancer
Evangelist
Forum|alt.badge.img+47
  • Evangelist
  • Best Answer
  • April 23, 2024

Something like this?

First the workspace adds all missing Area + Date combinations.

Then the consecutive occurences are counted. The AttributeManager uses Adjacent Feature Attributes, the Statistics Calculator gets the maximum values.

Some areas are missing from the results, so they are added in the last step.

 


geomancer
Evangelist
Forum|alt.badge.img+47
  • Evangelist
  • April 23, 2024

Funny, I answered a related question of you last week 😃

 


alejacd
Contributor
Forum|alt.badge.img+1
  • Author
  • Contributor
  • April 23, 2024

Thank you!

It seems it is what I was looking for. 

Can you maybe send it with an older version of fme? 2022.2

 

 


geomancer
Evangelist
Forum|alt.badge.img+47
  • Evangelist
  • April 23, 2024

I've added a FME 2020 version of the workspace to this reaction (as I don't have 2021 or 2022 installed).

By the way, the conditional value using Adjacent Feature Attirbutes looks like this:

 


geomancer
Evangelist
Forum|alt.badge.img+47
  • Evangelist
  • April 23, 2024

I am not quite sure about my workspace though. Something like

Area Category Date
A Low 202301
A Low 202302
A Low 202303
A   202304
A   202305
A Low 202306
A Low 202307
A Low 202308
A Low 202309
A   202310
A High 202311
A   202312

will only give

Area Condition Consecutive
A Low 4

but maybe it should return

Area Condition Consecutive
A Low 4
A Low 3

 


geomancer
Evangelist
Forum|alt.badge.img+47
  • Evangelist
  • April 24, 2024

I changed the logic of determining the groups of consecutive occurences.

In the case I described above, this workspace returns 

Area Condition Consecutive
A Low 4
A Low 3

 


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