# Graph with percent change between bucket

**URL:** <https://discuss.elastic.co/t/graph-with-percent-change-between-bucket/91204>\
**Category:** Kibana\
**Created:** [June 28, 2017, 10:37pm UTC](https://discuss.elastic.co/t/graph-with-percent-change-between-bucket/91204 "2017-06-28T22:37:31Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![matfiz](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/matfiz/32/19631_2.png) [@matfiz](https://discuss.elastic.co/u/matfiz)\
**Post date:** [June 28, 2017, 10:37pm UTC](https://discuss.elastic.co/t/graph-with-percent-change-between-bucket/91204/1 "2017-06-28T22:37:32Z")

</div>

I have an index with Elasticsearch which contains (inter alia) date and weight fields. I create a date histogram with bucket size year and I would like to calculate (in meta-language) sth like: sum(weight[year])/sum(weight[year-1]).

I can create an aggregation sum(weight), but how to calculate a faction of bucket-to-bucket values?  
There is Serial Differencing Aggregation or Derivative, but it just subtracts the values between buckets and I need to divide them.

I will appreciate some clues how to achieve it.

---

<div class="post-metadata">

**Author:** ![matfiz](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/matfiz/32/19631_2.png) [@matfiz](https://discuss.elastic.co/u/matfiz)\
**Post date:** [June 28, 2017, 11:47pm UTC](https://discuss.elastic.co/t/graph-with-percent-change-between-bucket/91204/2 "2017-06-28T23:47:44Z")

</div>

Ok, I have managed to solve it using TImelion with the following query:  
`.es(index=myindex,timefield=year_date,metric=sum:weight).divide(.es(index=myindex,timefield=year_date,metric=sum:weight,offset=-1y)).multiply(100).subtract(100).bars()`

---

<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 26, 2017, 11:47pm UTC](https://discuss.elastic.co/t/graph-with-percent-change-between-bucket/91204/3 "2017-07-26T23:47:49Z")

</div>

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