# \[Kibana - Timelion\] - Average between different functions

**URL:** <https://discuss.elastic.co/t/kibana-timelion-average-between-different-functions/197089>\
**Category:** Kibana\
**Tags:** timelion\
**Created:** [August 28, 2019, 10:37am UTC](https://discuss.elastic.co/t/kibana-timelion-average-between-different-functions/197089 "2019-08-28T10:37:36Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![GitsBdr](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/gitsbdr/32/58828_2.png) [@GitsBdr](https://discuss.elastic.co/u/GitsBdr)\
**Post date:** [August 28, 2019, 10:37am UTC](https://discuss.elastic.co/t/kibana-timelion-average-between-different-functions/197089/1 "2019-08-28T10:37:36Z")

</div>

Hi all,

Thanks in advance for the time you would take for this

I created a timelion visu as below :

```
.es(index=myindex*,timefield=mytime).bars()
,.es(index=myindex*,timefield=mytime,offset=-1d).bars()
,.es(index=myindex*,timefield=mytime,offset=-2d).bars()
,.es(index=myindex*,timefield=mytime,offset=-3d).bars()
,.es(index=myindex*,timefield=mytime,offset=-4d).bars()
,.es(index=myindex*,timefield=mytime,offset=-5d).bars()
,.es(index=myindex*,timefield=mytime,offset=-6d).bars()
,.es(index=myindex*,timefield=mytime,offset=-7d).bars() 

```

With the date filter set to 'Today' and interval set to '1h'

So I get basically 24 vertical bars which are the different counts\_doc per hour per day piled up together.  
But how can I get the average of those now ? Don't want them piled up like it is so far.

For example, if at ~4pm I always get 10 docs every day, my vertical bar will be 70 high (sum), where I want it to be 10 (avg)  
I hope I'm clear enough

[edit] Assuming my english isn't good enough - below an example

What I have so far :

 ![image](https://us1.discourse-cdn.com/elastic/original/3X/2/4/24fd423aad6cc3ee10ac013f773c63b57b662d0b.png)  
As you can see, vertical bars are split up by day (what you don't want to) so I need to find a way to measure the average of those bars and display it as a single bar

Thanks  
Guillaume

---

<div class="post-metadata">

**Author:** ![Nathan\_Reese](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nathan_reese/32/84829_2.png) [@Nathan\_Reese](https://discuss.elastic.co/u/Nathan_Reese)\
**Post date:** [August 28, 2019, 6:09pm UTC](https://discuss.elastic.co/t/kibana-timelion-average-between-different-functions/197089/2 "2019-08-28T18:09:49Z")

</div>

You can use the `add` operator to add all of the series together and then the `divide` operator to get the average. The example below uses logs sample data set

```auto
.es(index=kibana_sample_data_logs*,timefield=@timestamp)
.add(.es(index=kibana_sample_data_logs*,timefield=@timestamp,offset=-1d))
.add(.es(index=kibana_sample_data_logs*,timefield=@timestamp,offset=-2d))
.add(.es(index=kibana_sample_data_logs*,timefield=@timestamp,offset=-3d))
.add(.es(index=kibana_sample_data_logs*,timefield=@timestamp,offset=-4d))
.add(.es(index=kibana_sample_data_logs*,timefield=@timestamp,offset=-5d))
.add(.es(index=kibana_sample_data_logs*,timefield=@timestamp,offset=-6d))
.divide(7).bars()

```

 ![12%20PM](https://us1.discourse-cdn.com/elastic/original/3X/b/2/b2f01d7cbeaeb20ba74f1bff7eb86c55e156dfe0.png)

Just to complete the example, here is the stacked daily counts using sample data

```auto
.es(index=kibana_sample_data_logs*,timefield=@timestamp).bars()
,.es(index=kibana_sample_data_logs*,timefield=@timestamp,offset=-1d).bars()
,.es(index=kibana_sample_data_logs*,timefield=@timestamp,offset=-2d).bars()
,.es(index=kibana_sample_data_logs*,timefield=@timestamp,offset=-3d).bars()
,.es(index=kibana_sample_data_logs*,timefield=@timestamp,offset=-4d).bars()
,.es(index=kibana_sample_data_logs*,timefield=@timestamp,offset=-5d).bars()
,.es(index=kibana_sample_data_logs*,timefield=@timestamp,offset=-6d).bars()

```

 ![27%20PM](https://us1.discourse-cdn.com/elastic/original/3X/b/9/b9995610f5ba260367850340d4fd01a8e102feb3.png)

---

<div class="post-metadata">

**Author:** ![GitsBdr](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/gitsbdr/32/58828_2.png) [@GitsBdr](https://discuss.elastic.co/u/GitsBdr)\
**Post date:** [August 28, 2019, 6:44pm UTC](https://discuss.elastic.co/t/kibana-timelion-average-between-different-functions/197089/3 "2019-08-28T18:44:00Z")

</div>

Hi @Nathan_Reese and thanks for your perfect answer

It works well for the count, thanks a lot - this is clever  
What about adding a metric now ? looks like it's not working anymore ... tried with avg or max on an integer

[edit] - working for metric=sum:myfield however ...

Thanks

---

<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:** [September 25, 2019, 6:44pm UTC](https://discuss.elastic.co/t/kibana-timelion-average-between-different-functions/197089/4 "2019-09-25T18:44:04Z")

</div>

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