# Divide Sums with conditions an d group by

**URL:** https://discuss.elastic.co/t/divide-sums-with-conditions-an-d-group-by/223437
**Category:** Kibana
**Created:** [March 13, 2020, 2:47am UTC](https://discuss.elastic.co/t/divide-sums-with-conditions-an-d-group-by/223437 "2020-03-13T02:47:25Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![AClerk](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/aclerk/32/55297_2.png) [@AClerk](https://discuss.elastic.co/u/AClerk)
#### Post date: [March 13, 2020, 2:47am UTC](https://discuss.elastic.co/t/divide-sums-with-conditions-an-d-group-by/223437/1 "2020-03-13T02:47:25Z")

</div>

Hi,  
I have documents that looks like

> ```
> {
> ...
> "_source": {
> ...
> "Number_2": 64,
> ...
> "Name_A": "RANDOM_A",
> ...
> "Number_1": 4,
> ...
> "Name_B": "RANDOM_B"
> },
> 
> ```

I would like to show a ratio calculation of the following

x = sum(number\_1) group by name\_a  
y = sum(number\_2) group by name\_a  
calculate x/y

so each value will be summed once, as unique. Then show it on a graph or a metric.  
Eventually, use this metric in a ML job.

_Example_  
_Number\_1 values = 4,4,8,8,16,32,32,32,32_  
_Number\_2 values = 64,64_

(4+4+8+8+16+32+32+32+32)/(64+64) = 168/128 = 0.76

How is that possible?  
I did a few tries and errors, but they all fail.

Thanks!

---

<div class="post-metadata">

### Author: ![cheiligers](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/cheiligers/32/73114_2.png) [@cheiligers](https://discuss.elastic.co/u/cheiligers)
#### Post date: [April 3, 2020, 5:14pm UTC](https://discuss.elastic.co/t/divide-sums-with-conditions-an-d-group-by/223437/2 "2020-04-03T17:14:47Z")

</div>

Hi @AClerk,  
I recommend using a Filter Ratio in a TSVB visualization with a Filter Ratio aggregation. There's a great description of how to set this up in this discuss Q&A on [computing and displaying a ratio](https://discuss.elastic.co/t/visual-builder-compute-and-display-a-ratio/128836). It's a slightly older post, and depending on the version of Kibana that you're running, you can also reference the [guide in the docs](https://www.elastic.co/guide/en/kibana/current/visualize.html).

---

<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: [May 1, 2020, 5:14pm UTC](https://discuss.elastic.co/t/divide-sums-with-conditions-an-d-group-by/223437/3 "2020-05-01T17:14:52Z")

</div>

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