# How to divide two fields for visualization?

**URL:** <https://discuss.elastic.co/t/how-to-divide-two-fields-for-visualization/221009>\
**Category:** Kibana\
**Created:** [February 26, 2020, 10:36am UTC](https://discuss.elastic.co/t/how-to-divide-two-fields-for-visualization/221009 "2020-02-26T10:36:24Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mattness](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mattness/32/52975_2.png) [@Mattness](https://discuss.elastic.co/u/Mattness)\
**Post date:** [February 26, 2020, 10:36am UTC](https://discuss.elastic.co/t/how-to-divide-two-fields-for-visualization/221009/1 "2020-02-26T10:36:24Z")

</div>

Hello,

I have been experimenting with visualizations and wanted to know if there is a way to divide the value of a field?

I would prefer not to have to write a script. I am looking for a simple "calculation" or "division" option in the tsvb/linechart visualizations but have not been able to find anything.

The closest I have come to success was doing a filter ratio in tsvb but somehow it always returns 0.

Any help is very much appreciated.

This is what I tried in tsvb so far. Maybe someone knows what I am doing wrong?  
I want to divide the field index\_stats.total.search.query\_time\_in\_millis by the field index\_stats.total.search.query\_total.

I tried all kinds of values for the numerator/denominator fields, the current input in the picture is not the only thing I tried. I also tried the names of the fields I want to divide.

 ![image](https://us1.discourse-cdn.com/elastic/original/3X/7/3/73ec7edc88ff240b8c61aef574db6cd8afd6bef5.png)

---

<div class="post-metadata">

**Author:** ![flash1293](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/flash1293/32/41227_2.png) [@flash1293](https://discuss.elastic.co/u/flash1293)\
**Post date:** [February 26, 2020, 10:51am UTC](https://discuss.elastic.co/t/how-to-divide-two-fields-for-visualization/221009/2 "2020-02-26T10:51:08Z")

</div>

You can use the `math` aggregation for this - add a new series, select `math` as operation, select the values you want to divide (Average of field1, count), give them names and enter the division operation as formula: `params.param1 / params.param2`:

 ![Screenshot 2020-02-26 at 11.50.37](https://us1.discourse-cdn.com/elastic/original/3X/e/9/e9545cffa1de2cefbbdc24c1f77706327808d9fe.png)

---

<div class="post-metadata">

**Author:** ![dmomi](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dmomi/32/47291_2.png) [@dmomi](https://discuss.elastic.co/u/dmomi)\
**Post date:** [February 27, 2020, 4:09am UTC](https://discuss.elastic.co/t/how-to-divide-two-fields-for-visualization/221009/3 "2020-02-27T04:09:42Z")

</div>

params.param1 / params.param2 is not working for me. Individually I am getting the results. but with divide operator it is showing no data to display.

---

<div class="post-metadata">

**Author:** ![Mattness](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mattness/32/52975_2.png) [@Mattness](https://discuss.elastic.co/u/Mattness)\
**Post date:** [February 27, 2020, 7:20am UTC](https://discuss.elastic.co/t/how-to-divide-two-fields-for-visualization/221009/4 "2020-02-27T07:20:36Z")

</div>

This only did half the trick. I get the right result now - thank you very much for that - but the values are not updating. Do you know why that is?

---

<div class="post-metadata">

**Author:** ![Mattness](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mattness/32/52975_2.png) [@Mattness](https://discuss.elastic.co/u/Mattness)\
**Post date:** [February 27, 2020, 8:10am UTC](https://discuss.elastic.co/t/how-to-divide-two-fields-for-visualization/221009/5 "2020-02-27T08:10:14Z")

</div>

Figured it out. I changed the metrics from average to derivative. Now everything updates. Ty.

---

<div class="post-metadata">

**Author:** ![flash1293](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/flash1293/32/41227_2.png) [@flash1293](https://discuss.elastic.co/u/flash1293)\
**Post date:** [February 27, 2020, 9:12am UTC](https://discuss.elastic.co/t/how-to-divide-two-fields-for-visualization/221009/6 "2020-02-27T09:12:19Z")

</div>

Can you screenshot your configuration like I did above?

---

<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 26, 2020, 9:12am UTC](https://discuss.elastic.co/t/how-to-divide-two-fields-for-visualization/221009/7 "2020-03-26T09:12:21Z")

</div>

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