# How to show the percentage of each terms in kibana dashboard

**URL:** <https://discuss.elastic.co/t/how-to-show-the-percentage-of-each-terms-in-kibana-dashboard/320873>\
**Category:** Kibana\
**Created:** [December 9, 2022, 10:22am UTC](https://discuss.elastic.co/t/how-to-show-the-percentage-of-each-terms-in-kibana-dashboard/320873 "2022-12-09T10:22:09Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![subash](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/subash/32/59912_2.png) [@subash](https://discuss.elastic.co/u/subash)\
**Post date:** [December 9, 2022, 10:22am UTC](https://discuss.elastic.co/t/how-to-show-the-percentage-of-each-terms-in-kibana-dashboard/320873/1 "2022-12-09T10:22:09Z")

</div>

Hello,

I'm working on a requirement where I'll have to create a dashboard that shows the Inbound traffic (in percentage) of each interface in the network.

I have the fields '_system.network.in.bytes_' having the inbound traffic value in bytes and '_system.network.name_' having values like **Ethernet** or **Ethernet2** or **Ethernet5** etc.,

I want to calculate the Total sum of _system.network.in.bytes_ and the sum of _system.network.in.bytes_ of each value in the _system.network.name_ field and then to calculate the percentage traffic of each network.

For example: (Total In bytes of Ethernet2 / Total In bytes) \* 100

I tried bucket script and filter ratio in TSVB but it is not giving the expected result.

Please help me to make it work. Thanks in advance.

---

<div class="post-metadata">

**Author:** ![Sandeep\_Raju](https://avatars.discourse-cdn.com/v4/letter/s/8797f3/32.png) [@Sandeep\_Raju](https://discuss.elastic.co/u/Sandeep_Raju)\
**Post date:** [December 9, 2022, 12:46pm UTC](https://discuss.elastic.co/t/how-to-show-the-percentage-of-each-terms-in-kibana-dashboard/320873/2 "2022-12-09T12:46:27Z")

</div>

You can use enhanced table plugin and create table using enhanced table by using computed column use your formula.

Else you can create a scripted field and use the same formula and use that scripted field.

---

<div class="post-metadata">

**Author:** ![subash](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/subash/32/59912_2.png) [@subash](https://discuss.elastic.co/u/subash)\
**Post date:** [December 9, 2022, 1:16pm UTC](https://discuss.elastic.co/t/how-to-show-the-percentage-of-each-terms-in-kibana-dashboard/320873/3 "2022-12-09T13:16:54Z")

</div>

Hi @Sandeep_Raju,

Thanks for responding.

For percentange calculation, I'll have to calculate Total sum of _system.network.in.bytes_ and the sum of _system.network.in.bytes_ of each _system.network.name_.

In enhanced data table, if I split the rows by _system.network.name_, I will get the sum of _system.network.in.bytes_ of each network name but I will miss the total sum. If so, then I cannot calculate the percentange.

I'm not sure how it can be achieved using scripted fields. Could you please give me some idea of how to use scripted field in this scenario?

---

<div class="post-metadata">

**Author:** ![Rajsekhar\_Haldar1](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rajsekhar_haldar1/32/114460_2.png) [@Rajsekhar\_Haldar1](https://discuss.elastic.co/u/Rajsekhar_Haldar1)\
**Post date:** [December 9, 2022, 1:29pm UTC](https://discuss.elastic.co/t/how-to-show-the-percentage-of-each-terms-in-kibana-dashboard/320873/4 "2022-12-09T13:29:18Z")

</div>

Hi @subash,  
You can use a painless script to generate a new field having the calculated value in percentage and then use that field in the kibana dashboard.

---

<div class="post-metadata">

**Author:** ![subash](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/subash/32/59912_2.png) [@subash](https://discuss.elastic.co/u/subash)\
**Post date:** [December 9, 2022, 1:36pm UTC](https://discuss.elastic.co/t/how-to-show-the-percentage-of-each-terms-in-kibana-dashboard/320873/5 "2022-12-09T13:36:05Z")

</div>

Hi @Rajsekhar_Haldar1, @Sandeep_Raju

Sorry, I forgot to mention this in the post.  
The sum and percentage calculation are based on the selected time range. If the user selects last 15 minutes in the time picker then we'll have to do percentage calculation with the data of last 15 mins.

Is this still possible using painless script?

---

<div class="post-metadata">

**Author:** ![Rajsekhar\_Haldar1](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rajsekhar_haldar1/32/114460_2.png) [@Rajsekhar\_Haldar1](https://discuss.elastic.co/u/Rajsekhar_Haldar1)\
**Post date:** [December 9, 2022, 1:46pm UTC](https://discuss.elastic.co/t/how-to-show-the-percentage-of-each-terms-in-kibana-dashboard/320873/6 "2022-12-09T13:46:12Z")

</div>

@subash ,  
You would have to use the time filter in top of dashboard and once the required the time range is selected then the calculation would be based on that time range only and the result will be displayed accordingly in your dashboard for that particular generated field.  
Thanks

---

<div class="post-metadata">

**Author:** ![subash](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/subash/32/59912_2.png) [@subash](https://discuss.elastic.co/u/subash)\
**Post date:** [December 12, 2022, 9:49am UTC](https://discuss.elastic.co/t/how-to-show-the-percentage-of-each-terms-in-kibana-dashboard/320873/7 "2022-12-12T09:49:41Z")

</div>

Hi @Rajsekhar_Haldar1 ,

I have no idea of how to use the painless script for generating a new field that stores the calculated value. Could you please help me with a sample code snippet, if any?

---

<div class="post-metadata">

**Author:** ![Marco\_Liberati](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/marco_liberati/32/82953_2.png) [@Marco\_Liberati](https://discuss.elastic.co/u/Marco_Liberati)\
**Post date:** [December 12, 2022, 10:25am UTC](https://discuss.elastic.co/t/how-to-show-the-percentage-of-each-terms-in-kibana-dashboard/320873/8 "2022-12-12T10:25:05Z")

</div>

Hi @subash

you can use Lens formula to achieve what you are looking for.  
The trick is to use the `overall_sum` function in formula to compute the percentage.

Here's a configuration example:

 ![Screenshot 2022-12-12 at 11.22.34](https://us1.discourse-cdn.com/elastic/original/3X/f/a/fabada1de60cf0a0e9a731e03ca098ddc7188857.png)

In the `Metrics` configuration you can find the formula:

```auto
100 * sum(system.network.in.bytes) / overall_sum(sum(system.network.in.bytes))

```

(Here `bytes` has been replaced with your `system.network.in.bytes` one)

---

<div class="post-metadata">

**Author:** ![subash](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/subash/32/59912_2.png) [@subash](https://discuss.elastic.co/u/subash)\
**Post date:** [December 12, 2022, 11:16am UTC](https://discuss.elastic.co/t/how-to-show-the-percentage-of-each-terms-in-kibana-dashboard/320873/9 "2022-12-12T11:16:06Z")

</div>

Thanks a lot!!!! @Marco_Liberati

I was struggling with painless script but didn't know that it is very much easier in lens.

---

<div class="post-metadata">

**Author:** ![Rajsekhar\_Haldar1](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rajsekhar_haldar1/32/114460_2.png) [@Rajsekhar\_Haldar1](https://discuss.elastic.co/u/Rajsekhar_Haldar1)\
**Post date:** [December 12, 2022, 11:25am UTC](https://discuss.elastic.co/t/how-to-show-the-percentage-of-each-terms-in-kibana-dashboard/320873/10 "2022-12-12T11:25:10Z")

</div>

Yes it is easier, thank you.

---

<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:** [January 9, 2023, 11:25am UTC](https://discuss.elastic.co/t/how-to-show-the-percentage-of-each-terms-in-kibana-dashboard/320873/11 "2023-01-09T11:25:31Z")

</div>

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