# How to divide two doc\_count values in aggregations

**URL:** <https://discuss.elastic.co/t/how-to-divide-two-doc-count-values-in-aggregations/312035>\
**Category:** Kibana\
**Created:** [August 12, 2022, 7:23pm UTC](https://discuss.elastic.co/t/how-to-divide-two-doc-count-values-in-aggregations/312035 "2022-08-12T19:23:00Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Chandana\_P](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/chandana_p/32/101366_2.png) [@Chandana\_P](https://discuss.elastic.co/u/Chandana_P)\
**Post date:** [August 12, 2022, 7:23pm UTC](https://discuss.elastic.co/t/how-to-divide-two-doc-count-values-in-aggregations/312035/1 "2022-08-12T19:23:00Z")

</div>

I want to perform division between two doc\_count values of unique fields obtained through "terms" bucket aggregation. Is there a way to do that?

---

<div class="post-metadata">

**Author:** ![Marius\_Dragomir](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/marius_dragomir/32/42087_2.png) [@Marius\_Dragomir](https://discuss.elastic.co/u/Marius_Dragomir)\
**Post date:** [August 12, 2022, 8:19pm UTC](https://discuss.elastic.co/t/how-to-divide-two-doc-count-values-in-aggregations/312035/2 "2022-08-12T20:19:19Z")

</div>

This can be achieved by using the Math aggregation in TSVB.

---

<div class="post-metadata">

**Author:** ![Chandana\_P](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/chandana_p/32/101366_2.png) [@Chandana\_P](https://discuss.elastic.co/u/Chandana_P)\
**Post date:** [August 12, 2022, 8:29pm UTC](https://discuss.elastic.co/t/how-to-divide-two-doc-count-values-in-aggregations/312035/3 "2022-08-12T20:29:25Z")

</div>

The math aggregation in my TSVB is disabled. Any idea on how to enable that?

---

<div class="post-metadata">

**Author:** ![Marius\_Dragomir](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/marius_dragomir/32/42087_2.png) [@Marius\_Dragomir](https://discuss.elastic.co/u/Marius_Dragomir)\
**Post date:** [August 12, 2022, 8:37pm UTC](https://discuss.elastic.co/t/how-to-divide-two-doc-count-values-in-aggregations/312035/4 "2022-08-12T20:37:20Z")

</div>

The math aggregation works only after you have another aggregation in the series. So configure the others first and then you can add the Math one.

> **[TSVB | Kibana Guide \[master\] | Elastic](https://www.elastic.co/guide/en/kibana/master/tsvb.html)**
>
> Consider the production components that are used to generate reports.

There are a few videos that walk you through TSVB:

[![](https://us1.discourse-cdn.com/elastic/original/3X/2/e/2e8ec5bc285e1a202c0ce1e4a0482a91a5f378bf.jpeg "Time Series Visual Builder in Kibana") ](https://www.youtube.com/watch?v=CNR-4kZ6v_E)

---

<div class="post-metadata">

**Author:** ![Chandana\_P](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/chandana_p/32/101366_2.png) [@Chandana\_P](https://discuss.elastic.co/u/Chandana_P)\
**Post date:** [August 12, 2022, 8:48pm UTC](https://discuss.elastic.co/t/how-to-divide-two-doc-count-values-in-aggregations/312035/5 "2022-08-12T20:48:08Z")

</div>

Thank you for the reply. I am doing a filter using the "match\_phrase" on a field. I hard-coded the value on which the filter works. is there a way that this value can be obtained from the user?. thanks in advance.

---

<div class="post-metadata">

**Author:** ![Chandana\_P](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/chandana_p/32/101366_2.png) [@Chandana\_P](https://discuss.elastic.co/u/Chandana_P)\
**Post date:** [August 16, 2022, 10:26pm UTC](https://discuss.elastic.co/t/how-to-divide-two-doc-count-values-in-aggregations/312035/6 "2022-08-16T22:26:44Z")

</div>

I have log data with 4 version numbers. I aggregated these into 4 buckets using terms aggrgation. Now I want a graph for the proportion of each version. How do I get the overall count of the logs to perform (count of documents in each bucket/count of all logs) in TSVB? essentially, how to do the sum on doc\_count of terms aggregation in TSVB?

---

<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 13, 2022, 10:26pm UTC](https://discuss.elastic.co/t/how-to-divide-two-doc-count-values-in-aggregations/312035/7 "2022-09-13T22:26:55Z")

</div>

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