# Math in TSVB (and how to handle 0 in the denominator)

**URL:** <https://discuss.elastic.co/t/math-in-tsvb-and-how-to-handle-0-in-the-denominator/352581>\
**Category:** Kibana\
**Created:** [February 6, 2024, 1:19am UTC](https://discuss.elastic.co/t/math-in-tsvb-and-how-to-handle-0-in-the-denominator/352581 "2024-02-06T01:19:53Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![adam.richey](https://avatars.discourse-cdn.com/v4/letter/a/7993a0/32.png) [@adam.richey](https://discuss.elastic.co/u/adam.richey)\
**Post date:** [February 6, 2024, 1:19am UTC](https://discuss.elastic.co/t/math-in-tsvb-and-how-to-handle-0-in-the-denominator/352581/1 "2024-02-06T01:19:53Z")

</div>

Some of my data for smaller time values may result in a divide by 0 error. At the moment, if this happens the whole visualization breaks and I can't see any columns even with correct data for that time period.

Is there any way to rewrite the math function so that it can handle this potential error but still display properly?

The current expression is:  
divide(subtract(params.MaxA, params.MinA), subtract(params.MaxB, params.MinB))

---

<div class="post-metadata">

**Author:** ![Marta\_Bondyra](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/marta_bondyra/32/102122_2.png) [@Marta\_Bondyra](https://discuss.elastic.co/u/Marta_Bondyra)\
**Post date:** [February 29, 2024, 10:21am UTC](https://discuss.elastic.co/t/math-in-tsvb-and-how-to-handle-0-in-the-denominator/352581/2 "2024-02-29T10:21:30Z")

</div>

You could use Lens formula to achieve what you want. Use `ifelse` function where you specify a condition. In the condition you can use `eq` function to compare the denominator to 0. Let me know if you need further guidance.

 ![Screenshot 2024-02-29 at 11.19.52](https://us1.discourse-cdn.com/elastic/original/3X/4/6/46fcb0cbaef37a1ad9ac65181d76927094f71516.jpeg)

---

<div class="post-metadata">

**Author:** ![adam.richey](https://avatars.discourse-cdn.com/v4/letter/a/7993a0/32.png) [@adam.richey](https://discuss.elastic.co/u/adam.richey)\
**Post date:** [March 5, 2024, 4:20am UTC](https://discuss.elastic.co/t/math-in-tsvb-and-how-to-handle-0-in-the-denominator/352581/3 "2024-03-05T04:20:10Z")

</div>

Hmm... Looks like that my version of Kibana doesn't include that detail in the Lens visualization. We're currently running v 7.8.1

---

<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:** [April 2, 2024, 4:20am UTC](https://discuss.elastic.co/t/math-in-tsvb-and-how-to-handle-0-in-the-denominator/352581/4 "2024-04-02T04:20:47Z")

</div>

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