# Kibana Visual builder Math expression error

**URL:** <https://discuss.elastic.co/t/kibana-visual-builder-math-expression-error/188718>\
**Category:** Kibana\
**Created:** [July 3, 2019, 1:13pm UTC](https://discuss.elastic.co/t/kibana-visual-builder-math-expression-error/188718 "2019-07-03T13:13:29Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![ravitandur](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ravitandur/32/4568_2.png) [@ravitandur](https://discuss.elastic.co/u/ravitandur)\
**Post date:** [July 3, 2019, 1:13pm UTC](https://discuss.elastic.co/t/kibana-visual-builder-math-expression-error/188718/1 "2019-07-03T13:13:29Z")

</div>

I am creating a line visualisation using Kibana Visual builder.  
I defined two SUM aggregations on fields ingestedsize and primarystore.  
Based on these two values I want to display % line.  
For this I used Math aggregation, and defined two variables as show in below figure and used the expression to calculate the percentage.  
But I am getting error "cannot divide by zero".

If I understand correctly, for any bucket, if the ps1 is zero we are getting the error. Is there any way to check if it is grater than 0 in expression.  
Hope I am able to explain the problem, if you need any further details please let me know.

 ![image](https://us1.discourse-cdn.com/elastic/original/3X/2/9/295a517557f8f1075f2f8648e0564c7410006627.png)

---

<div class="post-metadata">

**Author:** ![Brandon\_Kobel](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/brandon_kobel/32/14829_2.png) [@Brandon\_Kobel](https://discuss.elastic.co/u/Brandon_Kobel)\
**Post date:** [July 3, 2019, 4:02pm UTC](https://discuss.elastic.co/t/kibana-visual-builder-math-expression-error/188718/2 "2019-07-03T16:02:48Z")

</div>

Hey @ravitandur, which version of Kibana are you using? I'm unable to replicate the "cannot divide by zero" issue in Kibana 7.2.0.

---

<div class="post-metadata">

**Author:** ![ravitandur](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ravitandur/32/4568_2.png) [@ravitandur](https://discuss.elastic.co/u/ravitandur)\
**Post date:** [July 4, 2019, 8:32am UTC](https://discuss.elastic.co/t/kibana-visual-builder-math-expression-error/188718/3 "2019-07-04T08:32:27Z")

</div>

We are using elastic 6.6.1.  
while you are testing, in any bucket, is denominator value was zero?  
In my case, in some if the buckets we can except zero value as a output of aggregation we are using in calculation.

---

<div class="post-metadata">

**Author:** ![Brandon\_Kobel](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/brandon_kobel/32/14829_2.png) [@Brandon\_Kobel](https://discuss.elastic.co/u/Brandon_Kobel)\
**Post date:** [July 5, 2019, 2:48pm UTC](https://discuss.elastic.co/t/kibana-visual-builder-math-expression-error/188718/4 "2019-07-05T14:48:48Z")

</div>

Hey @ravitandur would you mind creating a [bug](https://github.com/elastic/kibana/issues/new?template=Bug_report.md) for this? It looks like even in Kibana 7.2 if you divide by zero there is an issue, just instead of displaying the "cannot divide by 0" error we're now displaying "No data to display for the selected metrics" .

---

<div class="post-metadata">

**Author:** ![Brandon\_Kobel](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/brandon_kobel/32/14829_2.png) [@Brandon\_Kobel](https://discuss.elastic.co/u/Brandon_Kobel)\
**Post date:** [July 5, 2019, 2:50pm UTC](https://discuss.elastic.co/t/kibana-visual-builder-math-expression-error/188718/5 "2019-07-05T14:50:11Z")

</div>

In the mean-time, you could potentially use the [clamp](https://github.com/elastic/tinymath/blob/master/docs/functions.md#clamp-a--min--max-) function to prevent this from being zero.

---

<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:** [August 2, 2019, 2:50pm UTC](https://discuss.elastic.co/t/kibana-visual-builder-math-expression-error/188718/6 "2019-08-02T14:50:11Z")

</div>

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