# Calculate the percentage in the table using already aggregated fields

**URL:** <https://discuss.elastic.co/t/calculate-the-percentage-in-the-table-using-already-aggregated-fields/288921>\
**Category:** Kibana\
**Created:** [November 10, 2021, 6:52pm UTC](https://discuss.elastic.co/t/calculate-the-percentage-in-the-table-using-already-aggregated-fields/288921 "2021-11-10T18:52:55Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Michael\_Derevyanko](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/michael_derevyanko/32/96977_2.png) [@Michael\_Derevyanko](https://discuss.elastic.co/u/Michael_Derevyanko)\
**Post date:** [November 10, 2021, 6:52pm UTC](https://discuss.elastic.co/t/calculate-the-percentage-in-the-table-using-already-aggregated-fields/288921/1 "2021-11-10T18:52:55Z")

</div>

Hi

I have a question. Dose it possible to calculate the percentage using already aggregated fields.  
I have two columns aggregated and grouped by Buckets ( split rows was used):

- Sum of items (jmeter.count)
- Sum of items (jmeter.success\_count)

 ![image](https://us1.discourse-cdn.com/elastic/original/3X/5/9/59c83a7351233eace710fdd746eb625b0aa27b58.png)

I want to have a new column with calculation represented in percentage  
jmeter.success\_count/jmeter.count

What is the solution to archive that?

Any alternatives to visualize?

---

<div class="post-metadata">

**Author:** ![brianseeders](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/brianseeders/32/84831_2.png) [@brianseeders](https://discuss.elastic.co/u/brianseeders)\
**Post date:** [November 10, 2021, 9:06pm UTC](https://discuss.elastic.co/t/calculate-the-percentage-in-the-table-using-already-aggregated-fields/288921/2 "2021-11-10T21:06:56Z")

</div>

Hey @Michael_Derevyanko,

I don't think you can do this with a data table in Visualize, but I think you can do this with a data table in Canvas!

Take a look at this tutorial:

> **[Using Data Table and Debug Elements in Canvas within Kibana](https://www.elastic.co/blog/kibana-canvas-data-table-and-debug-elements)**
>
> Learn how to work with the Data Table and Debug elements in Canvas, using a sample data set built-into Elasticsearch and Kibana.

Using the sample data that comes with Kibana, I crafted the following data table in Canvas, which I believe mirrors what you're trying to achieve:

```auto
filters
| essql query="SELECT *, total_price/total_quantity as price_per_quantity FROM (SELECT geoip.continent_name, SUM(taxful_total_price) as total_price, SUM(total_quantity) as total_quantity FROM \"kibana_sample_data_ecommerce\" GROUP BY geoip.continent_name)"
| table
| render

```

And, just for readability, the SQL is:

```auto
SELECT *, total_price/total_quantity as price_per_quantity FROM
  (
    SELECT
      geoip.continent_name,
      SUM(taxful_total_price) as total_price,
      SUM(total_quantity) as total_quantity
    FROM "kibana_sample_data_ecommerce"
    GROUP BY geoip.continent_name
  )

```

Is that helpful? You would be grouping by request name and using jmeter values instead of the price/quantity.

Brian

---

<div class="post-metadata">

**Author:** ![Michael\_Derevyanko](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/michael_derevyanko/32/96977_2.png) [@Michael\_Derevyanko](https://discuss.elastic.co/u/Michael_Derevyanko)\
**Post date:** [November 11, 2021, 7:49am UTC](https://discuss.elastic.co/t/calculate-the-percentage-in-the-table-using-already-aggregated-fields/288921/3 "2021-11-11T07:49:03Z")

</div>

Many thanks @brianseeders will take a look for sure for that approach as well.

I have find out the solution to use TSVB table,

 ![image](https://us1.discourse-cdn.com/elastic/original/3X/9/c/9c32a60c859820cd9b76464bd7149c9bdec2daf4.png)

The result of usage

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

BR,  
Mike

---

<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:** [November 11, 2021, 9:26am UTC](https://discuss.elastic.co/t/calculate-the-percentage-in-the-table-using-already-aggregated-fields/288921/4 "2021-11-11T09:26:12Z")

</div>

Another solution would be to use Lens Formulas:

```auto
sum(jmeter.success_count) / sum(jmeter.count)

```

And set a Percent Formatter.

---

<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:** [December 9, 2021, 9:26am UTC](https://discuss.elastic.co/t/calculate-the-percentage-in-the-table-using-already-aggregated-fields/288921/5 "2021-12-09T09:26:47Z")

</div>

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