# Calculating average of values in a percentile

**URL:** <https://discuss.elastic.co/t/calculating-average-of-values-in-a-percentile/94413>\
**Category:** Elasticsearch\
**Created:** [July 25, 2017, 1:50am UTC](https://discuss.elastic.co/t/calculating-average-of-values-in-a-percentile/94413 "2017-07-25T01:50:25Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Simon\_Oxwell](https://avatars.discourse-cdn.com/v4/letter/s/f17d59/32.png) [@Simon\_Oxwell](https://discuss.elastic.co/u/Simon_Oxwell)\
**Post date:** [July 25, 2017, 1:50am UTC](https://discuss.elastic.co/t/calculating-average-of-values-in-a-percentile/94413/1 "2017-07-25T01:50:25Z")

</div>

Hi,

I'm reproducing an old client report, and have discovered that what was reported as an average, was in fact the average of 90% of the available data (ie, the top 10% of the count of values was removed)

Is there a way of calculating the average of data that falls within the 90th percentile in Elasticsearch? I'm on Elasticsearch 5.4.0.

Thanks,

Simon

---

<div class="post-metadata">

**Author:** ![DPattee](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dpattee/32/37772_2.png) [@DPattee](https://discuss.elastic.co/u/DPattee)\
**Post date:** [July 25, 2017, 6:27am UTC](https://discuss.elastic.co/t/calculating-average-of-values-in-a-percentile/94413/2 "2017-07-25T06:27:22Z")

</div>

The percentiles aggregation should give you what you want... [https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-metrics-percentile-aggregation.html](https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-metrics-percentile-aggregation.html)

You don't have to ask for an array of percentiles, you can ask for just a single one.

---

<div class="post-metadata">

**Author:** ![Simon\_Oxwell](https://avatars.discourse-cdn.com/v4/letter/s/f17d59/32.png) [@Simon\_Oxwell](https://discuss.elastic.co/u/Simon_Oxwell)\
**Post date:** [July 25, 2017, 6:42am UTC](https://discuss.elastic.co/t/calculating-average-of-values-in-a-percentile/94413/3 "2017-07-25T06:42:59Z")

</div>

Hi DPattee,

From what I understand that will give me the value of the 90th percentile, but I can't see how to a calculate the average of all the values in my dataset (a bucket?) that are less than or equal to the 90th percentile.

Thanks,

Simon

---

<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:** [August 22, 2017, 6:42am UTC](https://discuss.elastic.co/t/calculating-average-of-values-in-a-percentile/94413/4 "2017-08-22T06:42:59Z")

</div>

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