# Comparing metric over two time duration under same index

**URL:** https://discuss.elastic.co/t/comparing-metric-over-two-time-duration-under-same-index/245964
**Category:** Kibana
**Created:** [August 21, 2020, 11:05pm UTC](https://discuss.elastic.co/t/comparing-metric-over-two-time-duration-under-same-index/245964 "2020-08-21T23:05:22Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![SUMANTA\_ROY](https://avatars.discourse-cdn.com/v4/letter/s/47e85d/32.png) [@SUMANTA\_ROY](https://discuss.elastic.co/u/SUMANTA_ROY)
#### Post date: [August 21, 2020, 11:05pm UTC](https://discuss.elastic.co/t/comparing-metric-over-two-time-duration-under-same-index/245964/1 "2020-08-21T23:05:22Z")

</div>

Hi,

I am trying to find a way to visualize a bar chart displaying a metric value side by side (two different time periods), from the same index.  
Example : Comparing avg. attendance of class for 15 days of April month with same of May when I have attendance for all days under same index  
Any thoughts which aggregation/filter can be used.

---

<div class="post-metadata">

### Author: ![stephenb](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/stephenb/32/40856_2.png) [@stephenb](https://discuss.elastic.co/u/stephenb)
#### Post date: [August 21, 2020, 11:31pm UTC](https://discuss.elastic.co/t/comparing-metric-over-two-time-duration-under-same-index/245964/2 "2020-08-21T23:31:54Z")

</div>

Yes you can do this.

EDIT : OOPS / apologies I did not read your request well you wanted a Bar Chart, I gave a line chart.... let me think about the bar chart but in the mean time here is a line chart 🙂

Create Visualization -\> TSVB

Set the time picker to the right time scale.

Under Panel Options Make sure to set the index pattern to your index pattern

 ![Screen Shot 2020-08-21 at 4.30.06 PM](https://us1.discourse-cdn.com/elastic/original/3X/2/8/282e9c0010472ee3a7ab7d4f199cfb62922e5fc8.png)

Create a times series  
Average of Field (the attendance field) it will need to be numerical. Where you see system.load.1 in my picture put your attendance count field.

 ![Screen Shot 2020-08-21 at 4.25.09 PM](https://us1.discourse-cdn.com/elastic/original/3X/0/7/076eccac71040432ec3ad35f33c0f13bba70a545.png)

Create Another Time Series  
Change the Color  
Open Options and Change the Offset  
And you will have 2 series of the same data offset by 14 Days  
Save and put on a Dashaboard.

 ![Screen Shot 2020-08-21 at 4.25.30 PM](https://us1.discourse-cdn.com/elastic/original/3X/1/8/18cdb282d23ae9fdeaf3eeec7cfea8d4bd4afa8c.png)

---

<div class="post-metadata">

### Author: ![cheiligers](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/cheiligers/32/73114_2.png) [@cheiligers](https://discuss.elastic.co/u/cheiligers)
#### Post date: [August 21, 2020, 11:46pm UTC](https://discuss.elastic.co/t/comparing-metric-over-two-time-duration-under-same-index/245964/3 "2020-08-21T23:46:02Z")

</div>

@SUMANTA_ROY, welcome to the community!  
This one got me scratching me head a bit but I _think_ I've worked out a way you can do this.  
I used the ecommerce sample data set that Kibana provides by default. I know it's not exactly the same as the data set you're working with but I hope it illustrates how you can achieve your desired visualization.

I was able to create the following visualization that shows and average of a metric (in your case, it would be the attendance count per day) on the Y-axis, bucketing with a split series on the date field, followed by setting the X-axis Sub aggregation as a Date histogram:

 ![Screen Shot 2020-08-21 at 16.43.03](https://us1.discourse-cdn.com/elastic/original/3X/f/f/ff81094c2607eb9d9f1f24bf6fb629c7b50a01ef.png)

You'll have to 'tweak' your Date Range aggregation math (change `now-10d/d -> now-5d/d` to `now-30d/d -> now-15d/d` and `now-5d/d -> now` to `now-15d/d -> now`) and you can add more date range buckets.

I hope that gets you to where you need to go!

---

<div class="post-metadata">

### Author: ![SUMANTA\_ROY](https://avatars.discourse-cdn.com/v4/letter/s/47e85d/32.png) [@SUMANTA\_ROY](https://discuss.elastic.co/u/SUMANTA_ROY)
#### Post date: [August 22, 2020, 2:48am UTC](https://discuss.elastic.co/t/comparing-metric-over-two-time-duration-under-same-index/245964/4 "2020-08-22T02:48:01Z")

</div>

Thanks for your response. I am sorry as I could not probably explain the requirement clearly and I probably over simplified with that example. In actual case those events happen randomly, so calculating the offset from one another is really difficult. Instead, I would have like to select the absolute time range if possible anyway and just compare the avg. between two time duration (fine with bar/line).

---

<div class="post-metadata">

### Author: ![SUMANTA\_ROY](https://avatars.discourse-cdn.com/v4/letter/s/47e85d/32.png) [@SUMANTA\_ROY](https://discuss.elastic.co/u/SUMANTA_ROY)
#### Post date: [August 22, 2020, 2:56am UTC](https://discuss.elastic.co/t/comparing-metric-over-two-time-duration-under-same-index/245964/5 "2020-08-22T02:56:41Z")

</div>

![sample](https://us1.discourse-cdn.com/elastic/original/3X/6/0/609a0e9882253fdd7432db280691a083e880ed35.jpeg)

---

<div class="post-metadata">

### Author: ![stephenb](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/stephenb/32/40856_2.png) [@stephenb](https://discuss.elastic.co/u/stephenb)
#### Post date: [August 22, 2020, 7:28pm UTC](https://discuss.elastic.co/t/comparing-metric-over-two-time-duration-under-same-index/245964/6 "2020-08-22T19:28:38Z")

</div>

Hi @SUMANTA_ROY

I think what you desire may be difficult but I did just realize That you can use the Line method I described above and Get the comparative bar charts

Today Kibana visualizations works off a single date range then with an offset from that, it does not readily support Two separate date ranges overlaid.

Elasticsearch does have JDBC ODBC connectors so perhaps you could use another visualization tool such Tableau.

Also there is support for Vega visualizations but those require custom programming.

One thing really cool about Elastic is that you could actually go to kabana GitHub repository and open your feature request and it could be considered / no promises.

Unfortunately, I think that is all I have for you...

Perhaps someone else can come up with something.

---

<div class="post-metadata">

### Author: ![SUMANTA\_ROY](https://avatars.discourse-cdn.com/v4/letter/s/47e85d/32.png) [@SUMANTA\_ROY](https://discuss.elastic.co/u/SUMANTA_ROY)
#### Post date: [August 22, 2020, 8:45pm UTC](https://discuss.elastic.co/t/comparing-metric-over-two-time-duration-under-same-index/245964/7 "2020-08-22T20:45:51Z")

</div>

Hi @stephenb - thanks for your response.

I will try out other visualization tools as suggested or probably need to find out a way to calculate the offset easily. Thanks again for your response.

---

<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 19, 2020, 8:45pm UTC](https://discuss.elastic.co/t/comparing-metric-over-two-time-duration-under-same-index/245964/8 "2020-09-19T20:45:52Z")

</div>

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