# Query to get percentiles of a calculated sum value

**URL:** <https://discuss.elastic.co/t/query-to-get-percentiles-of-a-calculated-sum-value/282800>\
**Category:** Elasticsearch\
**Tags:** eql-elastic-query-language\
**Created:** [August 30, 2021, 11:04am UTC](https://discuss.elastic.co/t/query-to-get-percentiles-of-a-calculated-sum-value/282800 "2021-08-30T11:04:05Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![ankitdevnalkar](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ankitdevnalkar/32/46158_2.png) [@ankitdevnalkar](https://discuss.elastic.co/u/ankitdevnalkar)\
**Post date:** [August 30, 2021, 11:04am UTC](https://discuss.elastic.co/t/query-to-get-percentiles-of-a-calculated-sum-value/282800/1 "2021-08-30T11:04:05Z")

</div>

Based on the query below, I want to find `percentile bucket` of the values I am getting from `date_histogram` aggregation.

Below is my working query to find the day-wise total for the last 7 days, I am not sure where should I add the query code to find the 80th percentile of `the daily sum of baseValueUnitAmount` as well as what aggregation I should use `percentiles_bucket` or `percentiles`?

my query :

```auto
{
 "query": {
    "bool": {
      "must": [],
      "filter": [
        {
          "bool": {
            "filter": [
              {
                "bool": {
                  "should": [
                    {
                      "match_phrase": {
                        "displayName.keyword": "Cold"
                      }
                    }
                  ],
                  "minimum_should_match": 1
                }
              },
              {
                "bool": {
                  "should": [
                    {
                      "match_phrase": {
                        "type.keyword": "send"
                      }
                    }
                  ],
                  "minimum_should_match": 1
                }
              }
            ]
          }
        },
        {
          "range": {
            "date": {
              "gte": "now-7d",
              "lte": "now",
              "format": "strict_date_optional_time"
            }
          }
        }
      ],
      "should": [],
      "must_not": []
    }
  },
"aggs": {
    "2": {
      "date_histogram": {
        "field": "date",
        "calendar_interval": "1d",
        "time_zone": "Asia/Calcutta",
        "min_doc_count": 1
      },
      "aggs": {
        "1": {
          "sum": {
            "field": "baseValueUnitAmount"
          }
        }
      }
    }
  },
  "_source": false,
  "fields": ["baseValueUnitAmount"]
}

```

---

<div class="post-metadata">

**Author:** ![ankitdevnalkar](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ankitdevnalkar/32/46158_2.png) [@ankitdevnalkar](https://discuss.elastic.co/u/ankitdevnalkar)\
**Post date:** [August 31, 2021, 12:43pm UTC](https://discuss.elastic.co/t/query-to-get-percentiles-of-a-calculated-sum-value/282800/2 "2021-08-31T12:43:39Z")

</div>

@Mark_Harwood can you help ?

---

<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 28, 2021, 12:44pm UTC](https://discuss.elastic.co/t/query-to-get-percentiles-of-a-calculated-sum-value/282800/3 "2021-09-28T12:44:07Z")

</div>

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