# Scripted fields to calculate %

**URL:** <https://discuss.elastic.co/t/scripted-fields-to-calculate/235114>\
**Category:** Kibana\
**Created:** [June 1, 2020, 5:52am UTC](https://discuss.elastic.co/t/scripted-fields-to-calculate/235114 "2020-06-01T05:52:01Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![katara](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/katara/32/60143_2.png) [@katara](https://discuss.elastic.co/u/katara)\
**Post date:** [June 1, 2020, 5:52am UTC](https://discuss.elastic.co/t/scripted-fields-to-calculate/235114/1 "2020-06-01T05:52:01Z")

</div>

Hi,  
I have a field in Kibana which would say if my ticket is passed or failed.

has\_passed is the field.  
I wanna write a scripted\_field based on this value.

`> target % = (count(has_passed='passed')/count(total)) *100`

how do i do this?

---

<div class="post-metadata">

**Author:** ![Marta\_Bondyra](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/marta_bondyra/32/102122_2.png) [@Marta\_Bondyra](https://discuss.elastic.co/u/Marta_Bondyra)\
**Post date:** [June 10, 2020, 4:10pm UTC](https://discuss.elastic.co/t/scripted-fields-to-calculate/235114/2 "2020-06-10T16:10:15Z")

</div>

Hi @katara,  
unfortunately, scripted fields are property of the document and not the index. You cannot use scripted field for storing aggregated data. Example: if you have document with `price` and `discount_price` you can calculate the % of the discount, but you cannot calculate average of price in the whole index.  
What might be helpful for your example is to create TSVB visualization with filter ratio. Check out the example here: [https://www.elastic.co/blog/how-to-display-data-as-a-percentage-in-kibana-visualizations](https://www.elastic.co/blog/how-to-display-data-as-a-percentage-in-kibana-visualizations)

---

<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 8, 2020, 4:10pm UTC](https://discuss.elastic.co/t/scripted-fields-to-calculate/235114/3 "2020-07-08T16:10:30Z")

</div>

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