# How to add a column that includes a mathematical operation

**URL:** <https://discuss.elastic.co/t/how-to-add-a-column-that-includes-a-mathematical-operation/250370>\
**Category:** Kibana\
**Created:** [September 29, 2020, 2:11pm UTC](https://discuss.elastic.co/t/how-to-add-a-column-that-includes-a-mathematical-operation/250370 "2020-09-29T14:11:51Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Max\_Handle](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/max_handle/32/48133_2.png) [@Max\_Handle](https://discuss.elastic.co/u/Max_Handle)\
**Post date:** [September 29, 2020, 2:11pm UTC](https://discuss.elastic.co/t/how-to-add-a-column-that-includes-a-mathematical-operation/250370/1 "2020-09-29T14:11:51Z")

</div>

Hi,  
I am trying to create a column that calculates the average Session Percentage. The operation is quite simple: take the session Total of each row and divide it by the overall session total. So in this case the "Session Percentage" for "main" would be: 202/ (202+0+146) = 59.7%. I really appreciate the help!

 ![Bildschirmfoto 2020-09-29 um 16.03.00](https://us1.discourse-cdn.com/elastic/original/3X/d/1/d106723756b79ada4c3e0d226c5fba508ec5d4f1.png)

---

<div class="post-metadata">

**Author:** ![Wolfram\_Haussig](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/wolfram_haussig/32/70528_2.png) [@Wolfram\_Haussig](https://discuss.elastic.co/u/Wolfram_Haussig)\
**Post date:** [September 30, 2020, 10:27am UTC](https://discuss.elastic.co/t/how-to-add-a-column-that-includes-a-mathematical-operation/250370/2 "2020-09-30T10:27:35Z")

</div>

Hello Max,

What problem do you have with it? Do you not know where to start or have you already tried and got an error message?

If I understand you right you do not want to reindex all data to add the calculation result. Instead you want to add a column which is calculated just in time. In this case, Kibanas scripted fields are for you(beware that this might affect performance!): [Scripted fields](https://www.elastic.co/guide/en/kibana/current/scripted-fields.html)

So you could go to the Kibana Admin page, select the Index pattern and add a scripted field like(untested code!):

```auto
doc['main'].value / (doc['main'].value + doc['ResetUserData'].value + doc['MediaService'].value)

```

Best regards  
Wolfram

---

<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 28, 2020, 10:27am UTC](https://discuss.elastic.co/t/how-to-add-a-column-that-includes-a-mathematical-operation/250370/3 "2020-10-28T10:27:52Z")

</div>

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