# Average bucket is not working

**URL:** https://discuss.elastic.co/t/average-bucket-is-not-working/202928
**Category:** Kibana
**Created:** [October 10, 2019, 1:12am UTC](https://discuss.elastic.co/t/average-bucket-is-not-working/202928 "2019-10-10T01:12:47Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![Yungyoung\_Ok](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/yungyoung_ok/32/43465_2.png) [@Yungyoung\_Ok](https://discuss.elastic.co/u/Yungyoung_Ok)
#### Post date: [October 10, 2019, 1:12am UTC](https://discuss.elastic.co/t/average-bucket-is-not-working/202928/1 "2019-10-10T01:12:47Z")

</div>

I use average bucket to calculate tps.

**First, Working case**  
aggregation: average bucket  
bucket: date histogram, field: @timestamp, minimum interval: second  
**metric: count**

 ![image](https://us1.discourse-cdn.com/elastic/original/3X/3/a/3a5dcb71dc374bd8ecda3d53ee0eb6ea5daedbc1.png)

this case, is ok.  
inspect:

 ![image](https://us1.discourse-cdn.com/elastic/original/3X/8/b/8bc4dfa05eeb761675bba2d0e7d3da3a178116e4.png)  
 ![image](https://us1.discourse-cdn.com/elastic/original/3X/2/e/2ed76b3c2b0776504852b1d5a963402aede203e1.png)

The calculation process looks like below......

1. count per bucket
2. calculate average count  
**3. average count / minimum interval: second(3h = 10800)**

* * *

**Second, Not Working case**  
aggregation: average bucket  
bucket: date histogram, field: @timestamp, minimum interval: second  
**metric: unique count** , field: primary key field

 ![image](https://us1.discourse-cdn.com/elastic/original/3X/9/c/9c8fd32eb3942305efc82c2cb858b6d30a883bdf.png)

inspect:

 ![image](https://us1.discourse-cdn.com/elastic/original/3X/4/3/43c3569bc99a75c51c7711169c42e4fbc52c5cf9.png)  
 ![image](https://us1.discourse-cdn.com/elastic/original/3X/f/5/f5765d9780efee1318420d36e46324a03d3bf8b0.png)

The calculation process looks like below......  
1.unique count per bucket  
2. calculate average unique count

**why don't calculate process 3???**  
**(average unique count /minimum interval: second(3h = 10800)**

---

<div class="post-metadata">

### Author: ![markov00](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/markov00/32/33316_2.png) [@markov00](https://discuss.elastic.co/u/markov00)
#### Post date: [October 28, 2019, 5:11pm UTC](https://discuss.elastic.co/t/average-bucket-is-not-working/202928/2 "2019-10-28T17:11:26Z")

</div>

Hi @Yungyoung_Ok  
I've tested locally and I can reproduce this behaviour. Unfortunately it seems a bug. Do you mind to open an issue here: [https://github.com/elastic/kibana/issues/new?template=Bug\_report.md](https://github.com/elastic/kibana/issues/new?template=Bug_report.md)

The problem seems exactly the one you highlighted: the `1` aggregation value (67.162162 or 16.405) is the average of the returned buckets. The interval is internally reconfigured to a safer value (from a bucket every second to a 3h bucket). When the interval is reconfigured, we should divide the average but that number. This happens for the standard count but not for the unique unfortunately

---

<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 25, 2019, 5:11pm UTC](https://discuss.elastic.co/t/average-bucket-is-not-working/202928/3 "2019-11-25T17:11:27Z")

</div>

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