Grouping by events with not unique ID

Hello,

I’m trying to make grouping of occurring events to make some operations on it, but I struggle with robust way to filtrate duplicates and then there is a mistake in a math.

At this moment I make a window longer than all events, group by event ID and then do my work (usually sum, mean, median it depends). Everything is fine until event starts just before end of time window and ends in the next time window. Then I receive 2 groups for the same event so if I count number of events I got one (or more) too many. If I sum up the result is wrong and so on.
At this moment most of the time I tend to use 1 day time window so number of errors is quite limited but not zero.
You could advise me to filtrate it one more time using event ID, but it is a problem, event ID is not unique. It is a number counting from zero and it is reset once a week, but it is general rule, sometimes it is reset more often or I get so little number of events that after resetting I can get the same event ID within one day.

The solution for me would be quite easy in any programming language, as I would split events whenever I got 0 value, but I can’t achieve that in flux.

I hope my attached example will explain everything which I haven’t explain correctly:
image

Hello @XXYYZZ,
You’re correct this is non trivial with flux.
Here I did something similar

But yikes.

I honestly would recommend querying the data with API or client library and doing this processing elsewhere and writing the data back into influxdb.

Sorry I can’t be of better assistance.