# Calculate Percentage in Kibana

**URL:** <https://discuss.elastic.co/t/calculate-percentage-in-kibana/147518>\
**Category:** Kibana\
**Created:** [September 6, 2018, 7:43am UTC](https://discuss.elastic.co/t/calculate-percentage-in-kibana/147518 "2018-09-06T07:43:46Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Divit\_Sharma](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/divit_sharma/32/32348_2.png) [@Divit\_Sharma](https://discuss.elastic.co/u/Divit_Sharma)\
**Post date:** [September 6, 2018, 7:43am UTC](https://discuss.elastic.co/t/calculate-percentage-in-kibana/147518/1 "2018-09-06T07:43:46Z")

</div>

Can we calculate percentage in kibana. I have two fields. Count and count difference. I want to aggregate based on dept and calculate (count difference/count) \* 100 for the various dept buckets

Please help me

---

<div class="post-metadata">

**Author:** ![ppisljar](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ppisljar/32/11588_2.png) [@ppisljar](https://discuss.elastic.co/u/ppisljar)\
**Post date:** [September 6, 2018, 7:50am UTC](https://discuss.elastic.co/t/calculate-percentage-in-kibana/147518/2 "2018-09-06T07:50:09Z")

</div>

You could either reindex your data to already have this field or use scripted fields to achieve the same (but it will be way slower)

to do it with scripted fields:

- go to management, index patterns, select your index pattern, select scripted fields, add a new one
- in the script enter something like `return 100 * doc['field1name'].value / doc['field2name'].value`
- give it a name and save it, now you can use this field as any other

some docs:

- [https://www.elastic.co/blog/using-painless-kibana-scripted-fields](https://www.elastic.co/blog/using-painless-kibana-scripted-fields)
- [https://www.elastic.co/guide/en/kibana/current/scripted-fields.html](https://www.elastic.co/guide/en/kibana/current/scripted-fields.html)

---

<div class="post-metadata">

**Author:** ![Divit\_Sharma](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/divit_sharma/32/32348_2.png) [@Divit\_Sharma](https://discuss.elastic.co/u/Divit_Sharma)\
**Post date:** [September 6, 2018, 12:34pm UTC](https://discuss.elastic.co/t/calculate-percentage-in-kibana/147518/3 "2018-09-06T12:34:23Z")

</div>

Thanks I was able to use this. Can watcher be applied to this scripted field?

---

<div class="post-metadata">

**Author:** ![ppisljar](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ppisljar/32/11588_2.png) [@ppisljar](https://discuss.elastic.co/u/ppisljar)\
**Post date:** [September 6, 2018, 12:44pm UTC](https://discuss.elastic.co/t/calculate-percentage-in-kibana/147518/4 "2018-09-06T12:44:46Z")

</div>

i think that should be possible, however not completely sure.

---

<div class="post-metadata">

**Author:** ![Divit\_Sharma](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/divit_sharma/32/32348_2.png) [@Divit\_Sharma](https://discuss.elastic.co/u/Divit_Sharma)\
**Post date:** [September 6, 2018, 6:07pm UTC](https://discuss.elastic.co/t/calculate-percentage-in-kibana/147518/5 "2018-09-06T18:07:27Z")

</div>

I created a saved search and added a new scripted field %Count\_Difference using Count\_Diff and Count Field. Can that saved search be grouped by another field dept ?

---

<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:** [October 4, 2018, 6:07pm UTC](https://discuss.elastic.co/t/calculate-percentage-in-kibana/147518/6 "2018-10-04T18:07:32Z")

</div>

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