# Doing Complex Calculations in Kibana

**URL:** <https://discuss.elastic.co/t/doing-complex-calculations-in-kibana/86869>\
**Category:** Kibana\
**Created:** [May 23, 2017, 10:00pm UTC](https://discuss.elastic.co/t/doing-complex-calculations-in-kibana/86869 "2017-05-23T22:00:27Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Pulkit\_Sachdeva\_US](https://avatars.discourse-cdn.com/v4/letter/p/c2a13f/32.png) [@Pulkit\_Sachdeva\_US](https://discuss.elastic.co/u/Pulkit_Sachdeva_US)\
**Post date:** [May 23, 2017, 10:00pm UTC](https://discuss.elastic.co/t/doing-complex-calculations-in-kibana/86869/1 "2017-05-23T22:00:27Z")

</div>

Hi,

I have data from a survey coming into elastic search. I want to do visualizations for customer satisfaction, net promoter scores, etc. The issue I am facing are in calculation for these results.  
I am not able to include multiple fields in my calculation for these scores.

E.g.,

I have attached a sample record.

 ![](https://us1.discourse-cdn.com/elastic/original/3X/6/4/6426a4baafea081a18a6a132602cc539aa80d11a.PNG)

Now, the error on customer satisfaction score on records like these is calculated as  
1.96 \* POWER(cust\_sat\*(1-cust\_sat)/count(\*),0.5):

cust\_sat = sum(case when answer in ('4','5') then 1 end)/count(\*)

I am new to Kibana and cant seem to find a way to do this in Kibana.

An additional requirement is any filter I do on Kibana should result in this error number changing according to the filtered data.

Looking forward to getting helpful answers.

Thanks,  
Pulkit

---

<div class="post-metadata">

**Author:** ![warkolm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/warkolm/32/39224_2.png) [@warkolm](https://discuss.elastic.co/u/warkolm)\
**Post date:** [May 24, 2017, 5:58am UTC](https://discuss.elastic.co/t/doing-complex-calculations-in-kibana/86869/2 "2017-05-24T05:58:30Z")

</div>

You will need to use a scripted field to do this with the data already in ES - [https://www.elastic.co/guide/en/kibana/5.4/scripted-fields.html](https://www.elastic.co/guide/en/kibana/5.4/scripted-fields.html)

However you should consider doing this before you send it to ES, ie during the index process.

---

<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:** [June 21, 2017, 5:59am UTC](https://discuss.elastic.co/t/doing-complex-calculations-in-kibana/86869/3 "2017-06-21T05:59:35Z")

</div>

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