# How to use Derivative Aggs result to calculate percentage change?

**URL:** <https://discuss.elastic.co/t/how-to-use-derivative-aggs-result-to-calculate-percentage-change/230989>\
**Category:** Elasticsearch\
**Created:** [May 4, 2020, 3:13pm UTC](https://discuss.elastic.co/t/how-to-use-derivative-aggs-result-to-calculate-percentage-change/230989 "2020-05-04T15:13:44Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![vdalvi](https://avatars.discourse-cdn.com/v4/letter/v/54ee81/32.png) [@vdalvi](https://discuss.elastic.co/u/vdalvi)\
**Post date:** [May 4, 2020, 3:13pm UTC](https://discuss.elastic.co/t/how-to-use-derivative-aggs-result-to-calculate-percentage-change/230989/1 "2020-05-04T15:13:44Z")

</div>

Hi All,

I have the below query. How can I use the result/value of derivative aggs to calculate percentage change in each time interval? Basically I would love to divide the value of derivative aggs in each interval with the value in old interval? Any suggestions ?

```auto
GET indexname/_search
    {
      "query": {
        "range": {
          "timestamp": {
            "gte": "now-1h/h"
          }
        }
      },
      "size": 0,
      "aggs": {
        "get_cmtsId": {
          "terms": {
            "field": "cmtsId",
            "size": 5
          },
        "aggs": {
          "every30min": {
            "date_histogram": {
              "field": "timestamp",
              "fixed_interval": "30m"
              },
              "aggs": {
              "count_deriv": {
                "derivative": {
                  "buckets_path": "_count"
                }
                }
              } 
            }
          }
        }
      }
    }

```

---

<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:** [June 1, 2020, 3:13pm UTC](https://discuss.elastic.co/t/how-to-use-derivative-aggs-result-to-calculate-percentage-change/230989/2 "2020-06-01T15:13:46Z")

</div>

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