# Calculate average in Kibana visualizations

**URL:** <https://discuss.elastic.co/t/calculate-average-in-kibana-visualizations/152668>\
**Category:** Kibana\
**Created:** [October 16, 2018, 1:29pm UTC](https://discuss.elastic.co/t/calculate-average-in-kibana-visualizations/152668 "2018-10-16T13:29:52Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![andrsuh13](https://avatars.discourse-cdn.com/v4/letter/a/a9a28c/32.png) [@andrsuh13](https://discuss.elastic.co/u/andrsuh13)\
**Post date:** [October 16, 2018, 1:29pm UTC](https://discuss.elastic.co/t/calculate-average-in-kibana-visualizations/152668/1 "2018-10-16T13:29:52Z")

</div>

Hello,

I have a set of records which include

- times - how much times the event has been executed
- time\_sum - sum of events execution time.

Such events are published with interval of 5 seconds. I would like to visualize an average of execution time for every 5 minutes. What I should do is sum(times) for 5 minutes / sum(time\_sum) for 5 minutes for each 5 minutes. Does Kibana allow to do It using regular Kibana visualizations?

PS. I use Micrometer library for publishing metrics to Elasticsearch. And I asked the Micrometer's developers to give an ability to set different reporting step for metrics to avoid such aggregations on Kibana side. Here is the [link](https://github.com/micrometer-metrics/micrometer/issues/892).

---

<div class="post-metadata">

**Author:** ![timroes](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/timroes/32/19712_2.png) [@timroes](https://discuss.elastic.co/u/timroes)\
**Post date:** [October 16, 2018, 3:26pm UTC](https://discuss.elastic.co/t/calculate-average-in-kibana-visualizations/152668/2 "2018-10-16T15:26:17Z")

</div>

Hi,

what you are looking for is the bucket script aggregation, which allows you to calculate the outcome of several metric aggregations. This is not yet completely implemented in Kibana, see also [https://github.com/elastic/kibana/issues/4707](https://github.com/elastic/kibana/issues/4707)

Nevertheless you could actually achieve that (using Bucket Script aka Calculation) in Visual Builder, where you would just create two sum aggregations (for times and time\_sum) and then create a script, that will divide those two and draw this one.

The same could also be achieved in the more stable timelion visualization, by using a script that looks something like:

```auto
.es(metric=sum:times).divide(.es(metric=sum:time_sum))

```

And switching the interval selector to using `5m`.

Cheers,  
Tim

---

<div class="post-metadata">

**Author:** ![andrsuh13](https://avatars.discourse-cdn.com/v4/letter/a/a9a28c/32.png) [@andrsuh13](https://discuss.elastic.co/u/andrsuh13)\
**Post date:** [October 16, 2018, 5:15pm UTC](https://discuss.elastic.co/t/calculate-average-in-kibana-visualizations/152668/3 "2018-10-16T17:15:44Z")

</div>

Thank you for answer. I did It using Visual Builder. Very cool stuff! And the chart looks better than regular Kibana visualization!

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [November 13, 2018, 5:15pm UTC](https://discuss.elastic.co/t/calculate-average-in-kibana-visualizations/152668/4 "2018-11-13T17:15:46Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
