# Is it possible to do calculation on aggregated data in kibana

**URL:** <https://discuss.elastic.co/t/is-it-possible-to-do-calculation-on-aggregated-data-in-kibana/181531>\
**Category:** Kibana\
**Created:** [May 17, 2019, 7:33am UTC](https://discuss.elastic.co/t/is-it-possible-to-do-calculation-on-aggregated-data-in-kibana/181531 "2019-05-17T07:33:05Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![msk\_76](https://avatars.discourse-cdn.com/v4/letter/m/dbc845/32.png) [@msk\_76](https://discuss.elastic.co/u/msk_76)\
**Post date:** [May 17, 2019, 7:33am UTC](https://discuss.elastic.co/t/is-it-possible-to-do-calculation-on-aggregated-data-in-kibana/181531/1 "2019-05-17T07:33:05Z")

</div>

I have a timeseries (minute granularity) with a string field F1and numeric field F2 indexed ES.  
I would like to first do sum(F2) over the string field and then calculate time average. Example below :

For example :  
Time, F1, F2  
10:05, A, 2,  
10:10, A,3  
10:10, B,5  
10:15, A,3  
10:15, B,2

I want to aggregate SUM(F2) group by A, B both  
At the same time unique count(Time)

then SUM(F2)/unique count(Time) for A as well as B

My expected result should be  
Time , F1, F2  
10th hour, A, =SUM(2+3+3)/count unique(:05+:10,:15) =\> 8/3  
10th hour, B, =SUM(5+2)/count unique(:10, :15) =\> 7/2

Is it doable in kibana?

---

<div class="post-metadata">

**Author:** ![tylersmalley](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/tylersmalley/32/8833_2.png) [@tylersmalley](https://discuss.elastic.co/u/tylersmalley)\
**Post date:** [May 17, 2019, 5:12pm UTC](https://discuss.elastic.co/t/is-it-possible-to-do-calculation-on-aggregated-data-in-kibana/181531/2 "2019-05-17T17:12:38Z")

</div>

Everything except the unique, and that would really not be easy to do at query time since you would need to choose which record to select if there are duplicates.

My suggestion would be to ensure you don't have duplicates to begin with. How about including the time in the record ID, that way it wouldn't be possible to have duplicates?

---

<div class="post-metadata">

**Author:** ![msk\_76](https://avatars.discourse-cdn.com/v4/letter/m/dbc845/32.png) [@msk\_76](https://discuss.elastic.co/u/msk_76)\
**Post date:** [May 20, 2019, 3:08am UTC](https://discuss.elastic.co/t/is-it-possible-to-do-calculation-on-aggregated-data-in-kibana/181531/3 "2019-05-20T03:08:11Z")

</div>

I am not an expert of kibana. Not sure to understand your logic to implement in kibana. could you please elaborate how to calculate SUM(F2) group by A & B for each time\_stamp ?  
I think it's like a window function where window is a unique combination of time\_Stamp+F1 but don't know how to do it in kibana.

---

<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 17, 2019, 3:08am UTC](https://discuss.elastic.co/t/is-it-possible-to-do-calculation-on-aggregated-data-in-kibana/181531/4 "2019-06-17T03:08:20Z")

</div>

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