Solved

Count if event happened consecutively based on other variable.

  • 23 April 2024
  • 9 replies
  • 54 views

Badge +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!

icon

Best answer by geomancer 23 April 2024, 15:14

View original

9 replies

Userlevel 4
Badge +36

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?

Badge +1

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

Userlevel 4
Badge +36

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

I'll take a look.

Userlevel 4
Badge +36

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.

 

Userlevel 4
Badge +36

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

 

Badge +1

Thank you!

It seems it is what I was looking for. 

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

 

 

Userlevel 4
Badge +36

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:

 

Userlevel 4
Badge +36

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

 

Userlevel 4
Badge +36

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

 

Reply