Limit results based on percentage of sum aggregation

Hello All,

My goal is to limit the results based on a percentage of a sum aggregation. I will try to clarify it with an example.

{ "name": "A", "value": 10 }
{ "name": "B", "value": 20 }
{ "name": "B", "value": 35 }
{ "name": "A", "value": 15 }
{ "name": "C", "value": 15 }
{ "name": "A", "value": 10 }
{ "name": "C", "value": 5 }
{ "name": "A", "value": 10 }
{ "name": "D", "value": 15 }
{ "name": "A", "value": 30 }
{ "name": "E", "value": 1 }
(...)

Aggregating the data above,

{ "name": "A", "value": 70 }
{ "name": "B", "value": 60 }
{ "name": "C", "value": 50 }
{ "name": "D", "value": 45 }
{ "name": "E", "value": 40 }
(...)

Imagine that the sum of all values is equal to 640

I would like to show the items that together they represent 20% (or a bit more) of 640

640 * (20/100) = 128

So, the result that I would like to have is:

{ "name": "A", "value": 70 }
{ "name": "B", "value": 60 }

I will appreciate any thoughts.

Cheers,
Paulo

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