# Scripted field. Calculating percentage

**URL:** <https://discuss.elastic.co/t/scripted-field-calculating-percentage/66350>\
**Category:** Kibana\
**Created:** [November 17, 2016, 8:58am UTC](https://discuss.elastic.co/t/scripted-field-calculating-percentage/66350 "2016-11-17T08:58:04Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![TSimkevicius](https://avatars.discourse-cdn.com/v4/letter/t/b782af/32.png) [@TSimkevicius](https://discuss.elastic.co/u/TSimkevicius)\
**Post date:** [November 17, 2016, 8:58am UTC](https://discuss.elastic.co/t/scripted-field-calculating-percentage/66350/1 "2016-11-17T08:58:04Z")

</div>

Hello,

I want to as how to write script to calculate percentage. I want to calculate percentage of every industry in every state. Main problem is that I don't know how to write specific industry in specific state in script. I know it should look something like this ((specific industry in state) \* 100) /doc['industry.count'].

Thank you in advance.

---

<div class="post-metadata">

**Author:** ![tsullivan](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/tsullivan/32/31077_2.png) [@tsullivan](https://discuss.elastic.co/u/tsullivan)\
**Post date:** [November 17, 2016, 9:50pm UTC](https://discuss.elastic.co/t/scripted-field-calculating-percentage/66350/2 "2016-11-17T21:50:51Z")

</div>

Hi TSimkevicius,

You would need a field in your data for the (specific industry in state) in order to script a field like this.

If you don't have it, your best option to see the calculation in Kibana would be to run a calculation on the data in an ES query, and then index the result back into your data so you can work with it in Kibana.

If your data is time-based and seeing the data in a timeseries makes sense for your use case, you can maybe try Timelion which has an expression language that lets you do some calculations on data inside time buckets.

---

<div class="post-metadata">

**Author:** ![TSimkevicius](https://avatars.discourse-cdn.com/v4/letter/t/b782af/32.png) [@TSimkevicius](https://discuss.elastic.co/u/TSimkevicius)\
**Post date:** [November 18, 2016, 6:28am UTC](https://discuss.elastic.co/t/scripted-field-calculating-percentage/66350/3 "2016-11-18T06:28:50Z")

</div>

Thank you for your answer. I will try run calculation in an ES query.

---

<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 16, 2016, 6:28am UTC](https://discuss.elastic.co/t/scripted-field-calculating-percentage/66350/4 "2016-12-16T06:28:52Z")

</div>

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