# Calculation of percentages

**URL:** <https://discuss.elastic.co/t/calculation-of-percentages/295082>\
**Category:** Kibana\
**Created:** [January 21, 2022, 3:45pm UTC](https://discuss.elastic.co/t/calculation-of-percentages/295082 "2022-01-21T15:45:07Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![RaulSan](https://avatars.discourse-cdn.com/v4/letter/r/35a633/32.png) [@RaulSan](https://discuss.elastic.co/u/RaulSan)\
**Post date:** [January 21, 2022, 3:45pm UTC](https://discuss.elastic.co/t/calculation-of-percentages/295082/1 "2022-01-21T15:45:07Z")

</div>

Hello!  
I am somewhat of a newbie to Kibana. I'm not sure how to calculate percentages.  
I tell you my problem with a simple example.  
I have candies of different flavors bought in different stores. I have already eaten some of those candies.

My data could be:

STORE --- FLAVOR ---------- BOUGHT ------ EATEN

Store1 --- Lemon ----------10 ------------------ 2  
Store1 --- Strawberry ------6 ------------------ 3  
Store1 --- Mint ------------- 4 ------------------ 1  
Store2 --- Lemon ---------- 5 ------------------ 1  
Store2 ---Strawberry------- 6 ------------------ 4  
Store3 --- Lemon ----------- 5 ------------------ 3  
Store3 ---Strawberry -------8 ------------------ 2

Overall ----------------------- 44 ------------------16

How could you show the percentage of candies eaten out of the total candies bought?  
That is: (16\*100) / 44 = 36.4%

How could you show the total lemon candies from store1 eaten versus the total candies purchased?

That is: (2\*100)/44 =4.5%

How could you show the total number of lemon candies from the store1 eaten versus the lemon candies purchased?

That is: (2\*100)/20 =10%

Thanks for your help

---

<div class="post-metadata">

**Author:** ![Tomo\_M](https://avatars.discourse-cdn.com/v4/letter/t/848f3c/32.png) [@Tomo\_M](https://discuss.elastic.co/u/Tomo_M)\
**Post date:** [January 21, 2022, 6:00pm UTC](https://discuss.elastic.co/t/calculation-of-percentages/295082/2 "2022-01-21T18:00:08Z")

</div>

I suppose using Formula with Lens is a good way to visualize such data.

- store1 eaten versus the total candies purchased

 ![image](https://us1.discourse-cdn.com/elastic/original/3X/9/f/9fb2c6fdd4475911336eaea9647e10d9cbdc11ae.png)  
 ![image](https://us1.discourse-cdn.com/elastic/original/3X/5/d/5daf404975f00bdd5397b90279112d57a298c85b.png)

- the percentage of candies eaten out of the total candies bought

 ![image](https://us1.discourse-cdn.com/elastic/original/3X/8/b/8b03c3f6c5fbd9df1f1ee09c255c19d1457836b3.png)

- lemon candies from the store1 eaten versus the lemon candies purchased

 ![image](https://us1.discourse-cdn.com/elastic/original/3X/8/3/83ac2be3b6b0923677d1ca9d5d61a4317272aa8f.png)

The last one is a bit tricky because there is no function to sum by dimention made by top\_value.

If you have data with the following structure:  
STORE --- FLAVOR ---------- BOUGHT ------ EATEN  
Store1 --- Lemon ----------10 ------------------ 2  
↓  
STORE --- FLAVOR ---------- EATEN ------ COUNT  
Store1 --- Lemon ----------EATEN ------------------ 2  
Store1 --- Lemon ----------NOT\_EATEN ------------------ 8

You can use more flexible visualizations like Pie chart.

---

<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:** [February 18, 2022, 6:00pm UTC](https://discuss.elastic.co/t/calculation-of-percentages/295082/3 "2022-02-18T18:00:34Z")

</div>

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