# How to calculate the percentage in data table in kibana

**URL:** <https://discuss.elastic.co/t/how-to-calculate-the-percentage-in-data-table-in-kibana/284380>\
**Category:** Kibana\
**Created:** [September 16, 2021, 9:42am UTC](https://discuss.elastic.co/t/how-to-calculate-the-percentage-in-data-table-in-kibana/284380 "2021-09-16T09:42:48Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Nijanthan](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nijanthan/32/94663_2.png) [@Nijanthan](https://discuss.elastic.co/u/Nijanthan)\
**Post date:** [September 16, 2021, 9:42am UTC](https://discuss.elastic.co/t/how-to-calculate-the-percentage-in-data-table-in-kibana/284380/1 "2021-09-16T09:42:49Z")

</div>

How do I calculate the failure percentage in data table in kibana ?  
I have 3 columns like total ,success , failure nd I need to calculate the failure percentage which is ( failure / total ) ×100 . Is there any possible way to calculate it in data table

---

<div class="post-metadata">

**Author:** ![aaron-nimocks](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/aaron-nimocks/32/73965_2.png) [@aaron-nimocks](https://discuss.elastic.co/u/aaron-nimocks)\
**Post date:** [September 16, 2021, 9:48am UTC](https://discuss.elastic.co/t/how-to-calculate-the-percentage-in-data-table-in-kibana/284380/2 "2021-09-16T09:48:23Z")

</div>

You would do this using [scripted fields](https://www.elastic.co/guide/en/kibana/current/managing-index-patterns.html#scripted-fields) for versions below 7.14 or [runtime fields](https://www.elastic.co/guide/en/elasticsearch/reference/7.14/runtime.html) for 7.14 and later.

---

<div class="post-metadata">

**Author:** ![Nijanthan](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nijanthan/32/94663_2.png) [@Nijanthan](https://discuss.elastic.co/u/Nijanthan)\
**Post date:** [September 16, 2021, 9:50am UTC](https://discuss.elastic.co/t/how-to-calculate-the-percentage-in-data-table-in-kibana/284380/3 "2021-09-16T09:50:05Z")

</div>

As I'm new with kibana can you please help me with the scripted fields

---

<div class="post-metadata">

**Author:** ![aaron-nimocks](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/aaron-nimocks/32/73965_2.png) [@aaron-nimocks](https://discuss.elastic.co/u/aaron-nimocks)\
**Post date:** [September 16, 2021, 10:08am UTC](https://discuss.elastic.co/t/how-to-calculate-the-percentage-in-data-table-in-kibana/284380/4 "2021-09-16T10:08:37Z")

</div>

Index Management -\> Index Patterns -\> Open your index pattern -\> Scripted Fields Tab -\> Add Scripted Field

Name your field  
Set type as number

For the script you would use something like the below.

```auto
double result = (doc['failure'].value / doc['total'].value) * 100;

return result;

```

---

<div class="post-metadata">

**Author:** ![ghudgins](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ghudgins/32/138532_2.png) [@ghudgins](https://discuss.elastic.co/u/ghudgins)\
**Post date:** [September 16, 2021, 8:22pm UTC](https://discuss.elastic.co/t/how-to-calculate-the-percentage-in-data-table-in-kibana/284380/5 "2021-09-16T20:22:15Z")

</div>

if you're on 7.14 or later you can maybe do this in custom formula in lens tables. `(sum(failure) / sum(total)) * 100` (screenshots below)

there's this ratios example in this blog that does something similar with filtering (if you don't have a failure count if your document)

> **[10 common Kibana visualization questions answered with formulas and time travel](https://www.elastic.co/blog/kibana-10-common-questions-formulas-time-series-maps#proportion-of-errors)**
>
> Kibana advanced analytics features enable you to tackle time series and geospatial data questions. Learn how to use formulas for calculations like ratios, week over week, deviations, and others — plus Elastic Maps tips for time / space questions.

 ![image](https://us1.discourse-cdn.com/elastic/original/3X/1/6/16024ec5765de8cf15ff12203dfa41a39c26d7bf.png)  
 ![image](https://us1.discourse-cdn.com/elastic/original/3X/0/e/0e773bfdce88b775be6c06e24c72cedea09116a1.png)

---

<div class="post-metadata">

**Author:** ![Nijanthan](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nijanthan/32/94663_2.png) [@Nijanthan](https://discuss.elastic.co/u/Nijanthan)\
**Post date:** [September 17, 2021, 5:22am UTC](https://discuss.elastic.co/t/how-to-calculate-the-percentage-in-data-table-in-kibana/284380/6 "2021-09-17T05:22:58Z")

</div>

I'm using kibana 7.10.2 version

---

<div class="post-metadata">

**Author:** ![Nijanthan](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nijanthan/32/94663_2.png) [@Nijanthan](https://discuss.elastic.co/u/Nijanthan)\
**Post date:** [September 17, 2021, 7:23am UTC](https://discuss.elastic.co/t/how-to-calculate-the-percentage-in-data-table-in-kibana/284380/7 "2021-09-17T07:23:29Z")

</div>

The KQL query for failure is 'NOT statusCode:200'

---

<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 15, 2021, 7:23am UTC](https://discuss.elastic.co/t/how-to-calculate-the-percentage-in-data-table-in-kibana/284380/8 "2021-10-15T07:23:40Z")

</div>

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