Need to calculate a single value event rate and visualize it

I need to calculate the event rate and show it as a single value (metric).

E.g. I've the following documents:

Column 1 Column 2
Timestamp Data
1.2.2024 15:30 Event 1
1.2.2024 15:45 Event 2
2.2.2024 10:30 Event 3
2.2.2024 14:30 Event 4
2.2.2024 15:00 Event 5
3.2.2024 10:30 Event 6
...

If the user selects e.g. 2.2.2024 10:00-2.2.2024 15:00
Screenshot 2024-11-26 at 11.25.52
the calculation should be:
3/(2.2.2024 15:00-2.2.2024 10:30)

3=number of events in the selected timespan
(2.2.2024 15:00-2.2.2024 10:30)=timespan in seconds

Is this possible to add this as a visualization in Kibana?

Currently the rate function considers only the passed time range without checking the exact timestamp of the event.
So in your case the final formula would be:

3/(2.2.2024 15:00-2.2.2024 10:00)

In your case it looks like you're instead interested in the exact timing of the first event (10:30) but will like to stretch the final timespan until the end of the provided time range rather than the latest event (15:00 vs 14:30): did I get it correctly?

My example was a little bit misleading.

It would be best if I could get the timespan between the first and last event within the selected time range.

So if I select as time range: 2.2. 10:00 - 2.2. 15:15 the calculation should be done like this:
3/(2.2. 15:00 - 2.2. 10:30)

Ok, I see what you mean.
That is not possible yet. The rate function in ES currently has not that kind of precision to calculate the timespan: it will take into account the "date bucket" vs the specific event timing.

With this feature it would be possible to perform a precise rate as the one you're describing, so make sure to track it: [ES|QL] add rate agg · Issue #187753 · elastic/kibana · GitHub

Thanks for your answer

Where could I find the rate function in Kibana? I tried to insert it into a dashboard (e.g. as a metric) but can't find it.

Without ES|QL support it is really hard to compute right now in Kibana as a rate function requires a date histogram to be associated with it, and a Metric doesn't allow to define a rate + a date histogram without some tricks.
The only one I can think of is the compute of an average rate for a given time range:

  • select a Metric chart in Lens
  • Define a Date histogram break down and configure with a Collapse by Average

  • Now define a Counter Rate function as primary metric

Remember, this is just an average of all the rates for each time unit selected, so not the latest one.

Thank you very much!