Hi all.
Let's say that I have the following documents in an index
{
"user": "foo",
"cost": 10,
"revenue": 12
},
{
"user": "bar",
"cost": 20,
"revenue": 25
}
{
"user": "foo",
"cost": 15,
"revenue": 20
},
{
"user": "bar",
"cost": 15,
"revenue": 30
}
I need to create a Table visualization to show the margin and the margin_percent per user, where margin is sum of revenue - sum of cost and margin_percent is margin / sum of revenue.
For this example I should have:
| user | cost | revenue | margin | margin_percent |
| foo | 25 | 32 | 7 | 21.87 |
| bar | 35 | 55 | 20 | 36.36 |
I can easily add a calculated field in the index, margin = doc[revenue].value - doc[cost].value and then aggregate using a sum function, but how to calculate the margin_percent?
Any suggestion is appreciated.

