# Scripted fields need to calculate percentage

**URL:** https://discuss.elastic.co/t/scripted-fields-need-to-calculate-percentage/52051
**Category:** Kibana
**Created:** [June 7, 2016, 10:24am UTC](https://discuss.elastic.co/t/scripted-fields-need-to-calculate-percentage/52051 "2016-06-07T10:24:38Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![kumarts](https://avatars.discourse-cdn.com/v4/letter/k/ad7895/32.png) [@kumarts](https://discuss.elastic.co/u/kumarts)
#### Post date: [June 7, 2016, 10:24am UTC](https://discuss.elastic.co/t/scripted-fields-need-to-calculate-percentage/52051/1 "2016-06-07T10:24:38Z")

</div>

Hi  
I am trying to display the difference between 2 values eg: Plan spend versus Actual spend and Percentage of spend.

1. doc['PLAN-EXP'].value - doc['ACT-EXP'].value  
2.(doc['PLAN-EXP'].value - doc['ACT-EXP'].value)/sum(doc['ACT-EXP'].value)
2. (doc['PLAN-EXP'].value - doc['ACT-EXP'].value)/NAME.value)

Scripted Field 1 works but 2 & 3 does not work.

Or i need to some how access aggregation field here  
{  
"query": {"match\_all": {}},  
"aggs": {  
"NAME": {  
"sum": {  
"field": "ACT-EXP"  
}  
}  
},

pls help ...thanks

---

<div class="post-metadata">

### Author: ![shaunak](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/shaunak/32/6643_2.png) [@shaunak](https://discuss.elastic.co/u/shaunak)
#### Post date: [June 7, 2016, 7:57pm UTC](https://discuss.elastic.co/t/scripted-fields-need-to-calculate-percentage/52051/2 "2016-06-07T19:57:16Z")

</div>

Hi,

You might want to try using [Timelion](https://www.elastic.co/blog/timelion-timeline) for this type of charting.

---

<div class="post-metadata">

### Author: ![kumarts](https://avatars.discourse-cdn.com/v4/letter/k/ad7895/32.png) [@kumarts](https://discuss.elastic.co/u/kumarts)
#### Post date: [June 8, 2016, 2:20am UTC](https://discuss.elastic.co/t/scripted-fields-need-to-calculate-percentage/52051/3 "2016-06-08T02:20:07Z")

</div>

great thanks for the tips will try it out. cheers kumar

---

<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 6, 2017, 1:51pm UTC](https://discuss.elastic.co/t/scripted-fields-need-to-calculate-percentage/52051/4 "2017-07-06T13:51:13Z")

</div>


