# How to sum bucket aggregations in ranges

**URL:** <https://discuss.elastic.co/t/how-to-sum-bucket-aggregations-in-ranges/262602>\
**Category:** Kibana\
**Created:** [January 29, 2021, 6:53am UTC](https://discuss.elastic.co/t/how-to-sum-bucket-aggregations-in-ranges/262602 "2021-01-29T06:53:20Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![tahseen\_fatima](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/tahseen_fatima/32/67789_2.png) [@tahseen\_fatima](https://discuss.elastic.co/u/tahseen_fatima)\
**Post date:** [January 29, 2021, 6:53am UTC](https://discuss.elastic.co/t/how-to-sum-bucket-aggregations-in-ranges/262602/1 "2021-01-29T06:53:20Z")

</div>

Hi,

I have a ELK setup of 7.10.0v.  
I have created one data-table with **sum of brokerage** , Unique count of Client\_id and so on, now in the bucket I want to do the ranges on **sum of brokerage**. How can I take sum of brokerage in Range bucket of data table.

PFA for reference I have highlighted the columns of brokerage.

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

Kindly help,  
Tahseen

---

<div class="post-metadata">

**Author:** ![tahseen\_fatima](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/tahseen_fatima/32/67789_2.png) [@tahseen\_fatima](https://discuss.elastic.co/u/tahseen_fatima)\
**Post date:** [January 29, 2021, 10:39am UTC](https://discuss.elastic.co/t/how-to-sum-bucket-aggregations-in-ranges/262602/2 "2021-01-29T10:39:38Z")

</div>

Hi,

My data table query looks like this.

```
{
  "aggs": {
    "3": {
      "range": {
        "field": "brk_amt",
        "ranges": [
          {
            "from": 0,
            "to": 199
          },
          {
            "from": 200,
            "to": 499
          },
          {
            "from": 500
          }
        ],
        "keyed": true
      },
      "aggs": {
        "1": {
          "cardinality": {
            "field": "ent_id.keyword"
          }
        },
        "4": {
          "sum": {
            "field": "brk_amt"
          }
        }
      }
    }
  },
  "size": 0,
  "stored_fields": [
    "*"
  ],
  "script_fields": {},
  "docvalue_fields": [
    {
      "field": "@timestamp",
      "format": "date_time"
    },
    {
      "field": "creat_dt",
      "format": "date_time"
    },
    {
      "field": "ent_dob",
      "format": "date_time"
    },
    {
      "field": "long_trade_date",
      "format": "date_time"
    },
    {
      "field": "mapping_date",
      "format": "date_time"
    },
    {
      "field": "trade_date",
      "format": "date_time"
    }
  ],
  "_source": {
    "excludes": []
  },
  "query": {
    "bool": {
      "must": [],
      "filter": [
        {
          "match_all": {}
        },
        {
          "range": {
            "trade_date": {
              "gte": "2020-12-30T10:22:14.664Z",
              "lte": "2021-01-29T10:22:14.664Z",
              "format": "strict_date_optional_time"
            }
          }
        }
      ],
      "should": [],
      "must_not": []
    }
  }
}

```

In this I query it is taking the range of "brk\_amt", but in my case I want to take the range on sum of brk\_amt.

Please help to find a solution.

Regards,  
Tahseen

---

<div class="post-metadata">

**Author:** ![afharo](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/afharo/32/75202_2.png) [@afharo](https://discuss.elastic.co/u/afharo)\
**Post date:** [February 1, 2021, 3:23pm UTC](https://discuss.elastic.co/t/how-to-sum-bucket-aggregations-in-ranges/262602/3 "2021-02-01T15:23:07Z")

</div>

Hi @tahseen_fatima,

I understand from your question that you want to first sum the Brokerage, and then group them by ranges?

AFAIK, that kind of filter aggregation (Ranges) after a metric (Sum) is not supported by the core visualizations in Kibana. You might be able to achieve what you're after with Vega and their advanced usage.

Question aside: what would be the key to break your visualization for? AFAIK, if there's no initial _group by_ key, you'll only get 1 row in your table, won't you?

---

<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:** [March 1, 2021, 3:23pm UTC](https://discuss.elastic.co/t/how-to-sum-bucket-aggregations-in-ranges/262602/4 "2021-03-01T15:23:56Z")

</div>

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