# How can I show average by 2 month from TSVB?

**URL:** https://discuss.elastic.co/t/how-can-i-show-average-by-2-month-from-tsvb/234675
**Category:** Kibana
**Created:** [May 28, 2020, 7:08am UTC](https://discuss.elastic.co/t/how-can-i-show-average-by-2-month-from-tsvb/234675 "2020-05-28T07:08:36Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![Ethonwu](https://avatars.discourse-cdn.com/v4/letter/e/4bbf92/32.png) [@Ethonwu](https://discuss.elastic.co/u/Ethonwu)
#### Post date: [May 28, 2020, 7:08am UTC](https://discuss.elastic.co/t/how-can-i-show-average-by-2-month-from-tsvb/234675/1 "2020-05-28T07:08:37Z")

</div>

Hello , I am ELK rookie  
I have a small question wanna ask here  
How can I show average by 2 month from TSVB ?  
Here is sample data like this :

```
  date Execution Time Job Name
20200102 22 Job 1
20200102 33 Job 2
20200202 11 Job 1
20200205 45 Job 3
20200210 100 Job 5
20200311 10 Job 6
20200320 1 Job 9
20200417 55 Job 10

```

I want to show :

In X axis show every day  
and Y axis show average by 2 month like this :

20200102 ----\> (22+33) / 2 (Different Job Count by every day : Job1 and 2)  
Time range is from 20200102 to 20191102

2020202-----\> (11 + 22 + 33) / 3 (Different Job Count by every day : Job1 ,2 and Job 1 from 0202 )  
Time range is from 20200202 to 20191202

20200203 to 20200204 are no data , so is same as 20200202

20200205 -----\> ( 45 + 11 + 22 + 33 ) / 4  
Time range is from 20200205 to 20191205

20200210 -----\> ( 100 + 45 + 11 + 22 + 33 ) / 5  
Time range is from 20200210 to 20191210

20200311 -----\> (10 + 100 + 45 + 11 ) / 3  
Time range is from 20200311 to 20200111  
....

Please let me know if you have any comments 🙏 🙏

---

<div class="post-metadata">

### Author: ![wylie](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/wylie/32/81794_2.png) [@wylie](https://discuss.elastic.co/u/wylie)
#### Post date: [June 23, 2020, 7:36pm UTC](https://discuss.elastic.co/t/how-can-i-show-average-by-2-month-from-tsvb/234675/2 "2020-06-23T19:36:32Z")

</div>

It sounds like you want to use TSVB. Here's how I would set this up:

- Time interval is 1 month
- Time range is anything greater than 1 month, such as 6 months

For your series, I would define:

Sum of Execution time  
Unique count of Job Name  
Math:  
params.sum / params.count

This should get you the math you were looking for, if I understood it.

---

<div class="post-metadata">

### Author: ![Ethonwu](https://avatars.discourse-cdn.com/v4/letter/e/4bbf92/32.png) [@Ethonwu](https://discuss.elastic.co/u/Ethonwu)
#### Post date: [June 30, 2020, 8:26am UTC](https://discuss.elastic.co/t/how-can-i-show-average-by-2-month-from-tsvb/234675/3 "2020-06-30T08:26:44Z")

</div>

Thank for your suggestion !  
I successful show on TSVB  
I use **Moving Average** to fix time range problem, window size is 60 (2 month)  
I can't find Unique count from TSVB , so I use **count** and add Filter from option  
finally use Bucket Script sol the problem :  
params.moving\_sum / params.moving\_count

---

<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: [July 28, 2020, 8:26am UTC](https://discuss.elastic.co/t/how-can-i-show-average-by-2-month-from-tsvb/234675/4 "2020-07-28T08:26:45Z")

</div>

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