Scripted Field at aggregated level

Is it possible to create a scripted field that will calculate percentage variance at aggregate level?

For Example, the below data table is at detail level – the total variance that we are getting as 16 which is incorrect, instead it should be 6

Example 1
The below data table is at detail level – the total that we are getting is incorrect

Category Quantity 2019 Quantity 2018 Variance Percentage Variance
100A 10 8 2 1.25
100A 12 15 3 0.8
100A 15 12 3 1.25
100A 12 20 8 0.6
Total 100A 49 55 16 3.9

Example 2: We want it at aggregated level. The numbers below are correct.

Category Quantity 2019 Quantity 2018 Variance Percentage Variance
100A 49 55 6 0.89

Can anyone Please help me on this scenario?
Thanks in Advance.

Hello,

Scripted fields only work in the context of a single document, so they would not be able to do calculation at aggregation level.

Hi Marius,

Thanks for your response.
Is there someother way we can achieve this in kibana directly or it would be also fine i can do this in elasticsearch.

Thanks

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