# TSVB Table - Using Timepicker Duration as Interval

**URL:** <https://discuss.elastic.co/t/tsvb-table-using-timepicker-duration-as-interval/218826>\
**Category:** Kibana\
**Tags:** painless\
**Created:** [February 11, 2020, 4:44pm UTC](https://discuss.elastic.co/t/tsvb-table-using-timepicker-duration-as-interval/218826 "2020-02-11T16:44:34Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![seth.yes](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/seth.yes/32/11788_2.png) [@seth.yes](https://discuss.elastic.co/u/seth.yes)\
**Post date:** [February 11, 2020, 4:44pm UTC](https://discuss.elastic.co/t/tsvb-table-using-timepicker-duration-as-interval/218826/1 "2020-02-11T16:44:34Z")

</div>

I have some TSVB data tables (Kibana 7.4.2) I'm trying to modify to use a dynamically selected interval (timepicker range) for, and I can't find how to properly call this interval in Painless.

I currently have network data in a data table:

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

I am calculating the averages using a static (or otherwise nondescript) interval: `params._interval`.

 ![image](https://us1.discourse-cdn.com/elastic/original/3X/e/8/e8d92e5f4821b477ec2ac51a69736b63f5bf3744.png)  
The issue with this is that it does not dynamically scale with the timepicker:  
 ![image](https://us1.discourse-cdn.com/elastic/original/3X/5/c/5ce333b906bb2281f3683f68539f326240469e48.png)

My code to calculate the averages uses a painless script which references that `params._interval`:

```auto
(params.bytes * 8) / (params._interval / 1000)

```

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

What can I do to make these calculations use the timepicker range, rather than the interval? I desire to change the 'Data timerange mode' to 'Entire time range', however that leaves me with no results, presumably due to the 'entire time range' not being a valid `params._interval`:

 ![image](https://us1.discourse-cdn.com/elastic/original/3X/6/d/6dd5c94288adca1e6f43ea70604862d01ca2c945.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 12, 2020, 4:59pm UTC](https://discuss.elastic.co/t/tsvb-table-using-timepicker-duration-as-interval/218826/2 "2020-02-12T16:59:20Z")

</div>

The `derivative` aggregation has a `unit` parameter which should make this exact calculation taking the current interval into account on Elasticsearch side.

You can use this by putting a cumulative sum in front of it (to get rid of the derivative calculation, leaving just the unit conversion part):

 ![Screenshot 2020-02-12 at 17.57.07](https://us1.discourse-cdn.com/elastic/original/3X/a/7/a750063dc5ef075a0f31c9fcfe9585ae50680dce.png)

---

<div class="post-metadata">

**Author:** ![seth.yes](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/seth.yes/32/11788_2.png) [@seth.yes](https://discuss.elastic.co/u/seth.yes)\
**Post date:** [February 27, 2020, 9:28pm UTC](https://discuss.elastic.co/t/tsvb-table-using-timepicker-duration-as-interval/218826/3 "2020-02-27T21:28:11Z")

</div>

Thanks @flash1293. That solved it. I still had to start with a bucket script to convert:  
`bits = bytes * 8`  
However the rest of it works as expected. Thanks again!

---

<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:28pm UTC](https://discuss.elastic.co/t/tsvb-table-using-timepicker-duration-as-interval/218826/4 "2020-03-26T21:28:13Z")

</div>

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