# How to constrain sum metrics based on value of a count metric

**URL:** <https://discuss.elastic.co/t/how-to-constrain-sum-metrics-based-on-value-of-a-count-metric/197843>\
**Category:** Kibana\
**Created:** [September 3, 2019, 11:59am UTC](https://discuss.elastic.co/t/how-to-constrain-sum-metrics-based-on-value-of-a-count-metric/197843 "2019-09-03T11:59:07Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![stefws](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/stefws/32/6442_2.png) [@stefws](https://discuss.elastic.co/u/stefws)\
**Post date:** [September 3, 2019, 11:59am UTC](https://discuss.elastic.co/t/how-to-constrain-sum-metrics-based-on-value-of-a-count-metric/197843/1 "2019-09-03T11:59:07Z")

</div>

Got a table visualization bucktizing on two Term fields and then doing various split Metrics on other fields.  
Wondering if I might be able to filter out documents with 2. bucktize term seen more than once from other sum metrics, maybe through the Adv. JSON Input or otherwise or need I to dig into TimeLion maybe?

![42](https://us1.discourse-cdn.com/elastic/original/3X/2/7/27e451706dabcb9c8f4d2b06a37d68a4eda0241f.png)

Would like to calc sum of other columns with #metrics = 1 (#metrics is the 3. column, bucktized on 1. and 2. column)

 ![31](https://us1.discourse-cdn.com/elastic/original/3X/a/d/ad9f0bcc153781770f01e746498c0eb54052c2fd.png)

---

<div class="post-metadata">

**Author:** ![markov00](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/markov00/32/33316_2.png) [@markov00](https://discuss.elastic.co/u/markov00)\
**Post date:** [September 24, 2019, 3:30pm UTC](https://discuss.elastic.co/t/how-to-constrain-sum-metrics-based-on-value-of-a-count-metric/197843/2 "2019-09-24T15:30:24Z")

</div>

Hi @stefws  
sorry for the late reply. Have you already solved that issue?

If not can you provide me an example of output you want from the shared screenshot above?

---

<div class="post-metadata">

**Author:** ![stefws](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/stefws/32/6442_2.png) [@stefws](https://discuss.elastic.co/u/stefws)\
**Post date:** [September 24, 2019, 3:58pm UTC](https://discuss.elastic.co/t/how-to-constrain-sum-metrics-based-on-value-of-a-count-metric/197843/3 "2019-09-24T15:58:48Z")

</div>

Well sort of, wanted to filter out only rows where 3.column = 1 then calc total sum of columns 4. & 5.  
Believe this could be done with '{ "max\_doc\_count": 1 }' in adv. Json input of 3. column?  
But haven't tried it yet as mean time our BI people continued scrambling in their PowerBI&SQL 🙂

---

<div class="post-metadata">

**Author:** ![markov00](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/markov00/32/33316_2.png) [@markov00](https://discuss.elastic.co/u/markov00)\
**Post date:** [September 27, 2019, 1:37pm UTC](https://discuss.elastic.co/t/how-to-constrain-sum-metrics-based-on-value-of-a-count-metric/197843/4 "2019-09-27T13:37:42Z")

</div>

Unfortunately there is no `max_doc_count` as also described here: [https://github.com/elastic/elasticsearch/issues/21714](https://github.com/elastic/elasticsearch/issues/21714)

You could try with TSVB, but the only issue here is that you cannot group data by multiple fields (depends on your usecase, you can maybe reindex your data creating an field that crate an unique ID for these two fields)

---

<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:** [October 25, 2019, 1:37pm UTC](https://discuss.elastic.co/t/how-to-constrain-sum-metrics-based-on-value-of-a-count-metric/197843/5 "2019-10-25T13:37:47Z")

</div>

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