# Kibana TSVB Maths and 1st bucket

**URL:** https://discuss.elastic.co/t/kibana-tsvb-maths-and-1st-bucket/216972
**Category:** Kibana
**Created:** [January 29, 2020, 9:40am UTC](https://discuss.elastic.co/t/kibana-tsvb-maths-and-1st-bucket/216972 "2020-01-29T09:40:27Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![pchanas](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/pchanas/32/15311_2.png) [@pchanas](https://discuss.elastic.co/u/pchanas)
#### Post date: [January 29, 2020, 9:40am UTC](https://discuss.elastic.co/t/kibana-tsvb-maths-and-1st-bucket/216972/1 "2020-01-29T09:40:28Z")

</div>

Hi  
Moving to Kibana 7.4 (same with 7.5), I have an issue with a TSVB viz.

 ![image](https://us1.discourse-cdn.com/elastic/original/3X/b/c/bcc0a089fa7791c0efefa8d72dd3d292b1ebab31.png)

I have 2 time series (simple sum) : num and denom.  
I have to compute the ration in a Math agg:

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

I get the following:  
 ![image](https://us1.discourse-cdn.com/elastic/original/3X/8/7/875528d492f104247da08b295c1487e894f8934b.png)

By replacing the formula by `100 * (params.num / max(1, params.denom))` I can get the lines. Moreover computation of the 1st value is correct 🤪.

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

I think that there is mess with the first bucket... and by using max, something is "forced"... without the max, there is a divide by 0.

Same computation on same data works perfectly in 6.x.  
If someone has an idea..

Thansk in advance

---

<div class="post-metadata">

### Author: ![pchanas](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/pchanas/32/15311_2.png) [@pchanas](https://discuss.elastic.co/u/pchanas)
#### Post date: [January 29, 2020, 10:58am UTC](https://discuss.elastic.co/t/kibana-tsvb-maths-and-1st-bucket/216972/2 "2020-01-29T10:58:06Z")

</div>

Changing from Math aggs to bucket\_script makes it working fine...

---

<div class="post-metadata">

### Author: ![Bargs](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/bargs/32/5429_2.png) [@Bargs](https://discuss.elastic.co/u/Bargs)
#### Post date: [January 29, 2020, 8:07pm UTC](https://discuss.elastic.co/t/kibana-tsvb-maths-and-1st-bucket/216972/3 "2020-01-29T20:07:16Z")

</div>

If it's only the last bucket causing issues because it sometimes has no data, you can also try enabling the "Drop last bucket" option in the Panel options.

 ![image](https://us1.discourse-cdn.com/elastic/original/3X/f/e/fe5d16817c1ddef17be6d1fe85ec91c806793d58.png)

---

<div class="post-metadata">

### Author: ![pchanas](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/pchanas/32/15311_2.png) [@pchanas](https://discuss.elastic.co/u/pchanas)
#### Post date: [January 30, 2020, 7:47am UTC](https://discuss.elastic.co/t/kibana-tsvb-maths-and-1st-bucket/216972/4 "2020-01-30T07:47:16Z")

</div>

Drop last bucket is enabled.  
The first bucket is causing the issue.

---

<div class="post-metadata">

### Author: ![Bargs](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/bargs/32/5429_2.png) [@Bargs](https://discuss.elastic.co/u/Bargs)
#### Post date: [January 31, 2020, 8:40pm UTC](https://discuss.elastic.co/t/kibana-tsvb-maths-and-1st-bucket/216972/5 "2020-01-31T20:40:08Z")

</div>

Apologies, I see now you said that in your original post. You may have already found the best workaround with `max`. Depending on what version of 6.x you were using before, the change in behavior may be due to the [switch from math.js to tinymath](https://github.com/elastic/kibana/pull/16965).

---

<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: [February 28, 2020, 8:40pm UTC](https://discuss.elastic.co/t/kibana-tsvb-maths-and-1st-bucket/216972/6 "2020-02-28T20:40:14Z")

</div>

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