# Kibana Dynamically Time Filter

**URL:** <https://discuss.elastic.co/t/kibana-dynamically-time-filter/242940>\
**Category:** Kibana\
**Created:** [July 28, 2020, 4:25pm UTC](https://discuss.elastic.co/t/kibana-dynamically-time-filter/242940 "2020-07-28T16:25:41Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![alparslan](https://avatars.discourse-cdn.com/v4/letter/a/e19adc/32.png) [@alparslan](https://discuss.elastic.co/u/alparslan)\
**Post date:** [July 28, 2020, 4:25pm UTC](https://discuss.elastic.co/t/kibana-dynamically-time-filter/242940/1 "2020-07-28T16:25:41Z")

</div>

I need to show daily/weekly/monthly average of duration of my job with Gauge in Kibana.  
We can call this graph as daily/weekly/monthly load percente of machine.

I have `duration-time-in-day` field in index. want to sum duration-time-in-day and divide with selected range in day.

For example; my date time selection field is

> Jul 27, 2020 @ 00:00:00.000 -\> Jul 28, 2020 @ 00:00:00.000

its a single day.  
So that my requirement

> duration-time-in-day/1

or my other time filter selection

> last 7 days

> sum(duration-in-day for last 7 days) / 7

I try to use **Bucket script** may close for this. But i could not find to get the right way of the date range dynamically.

Any advice for this ?  
Thanks

---

<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:** [August 11, 2020, 5:31pm UTC](https://discuss.elastic.co/t/kibana-dynamically-time-filter/242940/2 "2020-08-11T17:31:03Z")

</div>

Hi @alparslan,  
I think what could do the trick in this case is to use TSVB.  
You need to setup interval of the duration of 1d (that'll guarantee that you have as many buckets as days). Then configure following metrics as on the screenshot below:

- count
- overall sum of count
- sum of `duration-time-in-day`
- overall sum of "sum of `duration-time-in-day`"
- math: `params.sum/params.sumOfCount`- we're dividing the whole duration by numbers of buckets

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

Let me know if it works for you!  
Cheers,  
Marta

---

<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:** [September 8, 2020, 5:31pm UTC](https://discuss.elastic.co/t/kibana-dynamically-time-filter/242940/3 "2020-09-08T17:31:11Z")

</div>

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