# Scripted field calculation with division

**URL:** <https://discuss.elastic.co/t/scripted-field-calculation-with-division/278284>\
**Category:** Kibana\
**Created:** [July 9, 2021, 1:48pm UTC](https://discuss.elastic.co/t/scripted-field-calculation-with-division/278284 "2021-07-09T13:48:30Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![jogabonito](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jogabonito/32/56737_2.png) [@jogabonito](https://discuss.elastic.co/u/jogabonito)\
**Post date:** [July 9, 2021, 1:48pm UTC](https://discuss.elastic.co/t/scripted-field-calculation-with-division/278284/1 "2021-07-09T13:48:30Z")

</div>

Hi

I want to make a scripted field using a simple calculation by using summation and dividing, but I just keep getting 0 and the error-message:  
"Unable to write index pattern! Refresh the page to get the most up to date changes for this index pattern."

I want to calculate the percentage of:  
(collected\_va + collected\_ems10) / (expected\_va + expected\_ems10)

All documents contains values in all 4 fields.  
expected\_va and expected\_ems10 is always greater than 0  
collected\_va and collected\_ems10 is always greater than 0

I use the following code:

(doc['collected\_va'].value + doc['collected\_ems10'].value) / (doc['expected\_va'].value + doc['expected\_ems10'].value)

What do I do wrong here?

---

<div class="post-metadata">

**Author:** ![flash1293](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/flash1293/32/41227_2.png) [@flash1293](https://discuss.elastic.co/u/flash1293)\
**Post date:** [July 9, 2021, 2:34pm UTC](https://discuss.elastic.co/t/scripted-field-calculation-with-division/278284/2 "2021-07-09T14:34:38Z")

</div>

> [@jogabonito](#):
>
> Unable to write index pattern

This means your user can't write the index pattern saved object, probably due to permission problems. Make sure your user has "All" permissions for the "Management \> Index pattern management" privilege.

---

<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:** [August 6, 2021, 2:35pm UTC](https://discuss.elastic.co/t/scripted-field-calculation-with-division/278284/3 "2021-08-06T14:35:18Z")

</div>

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