# Anyway to calculate the percentage of bucket value?

**URL:** https://discuss.elastic.co/t/anyway-to-calculate-the-percentage-of-bucket-value/110042
**Category:** Elasticsearch
**Created:** [December 3, 2017, 11:34am UTC](https://discuss.elastic.co/t/anyway-to-calculate-the-percentage-of-bucket-value/110042 "2017-12-03T11:34:13Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![hym](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/hym/32/22399_2.png) [@hym](https://discuss.elastic.co/u/hym)
#### Post date: [December 3, 2017, 11:34am UTC](https://discuss.elastic.co/t/anyway-to-calculate-the-percentage-of-bucket-value/110042/1 "2017-12-03T11:34:13Z")

</div>

Hi,  
I want to calculate the percentage of each bucket regarding the total value. as an example;  
let's assume we have sale per month calculated (for a couple of months) as follows:  
month1 -\> 10  
month2 -\> 25  
month3 -\> 15

I want to have the percentage of months too:  
month1 -\> 20%  
month2 -\> 50%  
month3 -\> 30%

I've tried bucket\_script but as it is a parent pipeline aggregation I cannot have access to the total value and what I have access to is the statistics of that individual bucket.

Is there any way to pass the total value inside bucket\_script?

Thanks in advance

---

<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: [December 31, 2017, 11:34am UTC](https://discuss.elastic.co/t/anyway-to-calculate-the-percentage-of-bucket-value/110042/2 "2017-12-31T11:34:19Z")

</div>

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