# Data Table: calculate average from output of two sum aggregations

**URL:** <https://discuss.elastic.co/t/data-table-calculate-average-from-output-of-two-sum-aggregations/130641>\
**Category:** Kibana\
**Created:** [May 4, 2018, 2:13pm UTC](https://discuss.elastic.co/t/data-table-calculate-average-from-output-of-two-sum-aggregations/130641 "2018-05-04T14:13:14Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![BradVido](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/bradvido/32/741_2.png) [@BradVido](https://discuss.elastic.co/u/BradVido)\
**Post date:** [May 4, 2018, 2:13pm UTC](https://discuss.elastic.co/t/data-table-calculate-average-from-output-of-two-sum-aggregations/130641/1 "2018-05-04T14:13:14Z")

</div>

Here's an example:

 ![image](https://us1.discourse-cdn.com/elastic/original/3X/e/0/e0fcab23f427096cb40ad6517ec2726239e5d203.png)

Currently the Gross Margin uses a script, and the problem is it calculates a percentage for every document. Averaging that percentage does not give the "overall average" because it's not weighted. e.g. a $100 deal with 95% Gross Margin is treated the same as a $1,000,000 deal with 5% Gross Margin. You can see this if you manually divide GM/Revenue in the results, the percentage doesn't match.

The obvious solution is to calculate the Gross Margin percentage based on the output of the two previous sum aggregations. The problem is I can't find any way to do that.

I'm using Elastic cloud and have the latest Kibana and ES software. I've been looking into pipeline aggregations, but seems like they aren't quite what I need.

I know this kind of math can be done in timelion graphs, but I need it in this data table.

Are there any solutions (I'm open to workarounds/hacks) to make this work?

---

<div class="post-metadata">

**Author:** ![lfroment-datasweet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/lfroment-datasweet/32/32908_2.png) [@lfroment-datasweet](https://discuss.elastic.co/u/lfroment-datasweet)\
**Post date:** [May 4, 2018, 2:57pm UTC](https://discuss.elastic.co/t/data-table-calculate-average-from-output-of-two-sum-aggregations/130641/2 "2018-05-04T14:57:33Z")

</div>

Elastic cloud doesnt support plugins, but you could do what you need in your own local E/K using this plugin : [https://github.com/datasweet-fr/kibana-datasweet-formula/](https://github.com/datasweet-fr/kibana-datasweet-formula/)

regards

Lionel

---

<div class="post-metadata">

**Author:** ![BradVido](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/bradvido/32/741_2.png) [@BradVido](https://discuss.elastic.co/u/BradVido)\
**Post date:** [May 4, 2018, 4:18pm UTC](https://discuss.elastic.co/t/data-table-calculate-average-from-output-of-two-sum-aggregations/130641/3 "2018-05-04T16:18:45Z")

</div>

Ahh, very nice. Is elastic cloud supporting plugins a feature on the roadmap or intentionally disabled?

---

<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 1, 2018, 4:18pm UTC](https://discuss.elastic.co/t/data-table-calculate-average-from-output-of-two-sum-aggregations/130641/4 "2018-06-01T16:18:57Z")

</div>

Closed on June 1, 2018, 4:18pm UTC

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