# How to do arithmetic calculations on the results from an Average Bucket

**URL:** <https://discuss.elastic.co/t/how-to-do-arithmetic-calculations-on-the-results-from-an-average-bucket/214793>\
**Category:** Elasticsearch\
**Created:** [January 13, 2020, 10:26am UTC](https://discuss.elastic.co/t/how-to-do-arithmetic-calculations-on-the-results-from-an-average-bucket/214793 "2020-01-13T10:26:40Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![fallicious](https://avatars.discourse-cdn.com/v4/letter/f/dc4da7/32.png) [@fallicious](https://discuss.elastic.co/u/fallicious)\
**Post date:** [January 13, 2020, 10:26am UTC](https://discuss.elastic.co/t/how-to-do-arithmetic-calculations-on-the-results-from-an-average-bucket/214793/1 "2020-01-13T10:26:41Z")

</div>

i am calculating the sum of time with daily interval and using it with the average bucket to get the total overall average, now i want to divide that result by the total number of users. but i cant seem to be able to do that with the result of the average bucket.

```
{
  "size": 0,
  "aggs": {
    "sum_per_day": {
      "date_histogram": {
        "field": "@timestamp",
        "calendar_interval": "day"
      },
      "aggs": {
        "time": {
          "sum": {
            "field": "timeSpent"
          }
        }
      }
    },
    "overall_average": {
      "avg_bucket": {
        "buckets_path": "sum_per_day>time"
      }
    }
  },
    "script_fields": {
      "avg_per_user": {
        "script": "aggregations.overall_average.value/30"
      }
    }
  }
```

---

<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:** [February 10, 2020, 10:26am UTC](https://discuss.elastic.co/t/how-to-do-arithmetic-calculations-on-the-results-from-an-average-bucket/214793/2 "2020-02-10T10:26:43Z")

</div>

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