Here's an example:
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?