# Average(wrt time) of Sum of Values

**URL:** https://discuss.elastic.co/t/average-wrt-time-of-sum-of-values/51556
**Category:** Kibana
**Created:** [June 1, 2016, 12:26pm UTC](https://discuss.elastic.co/t/average-wrt-time-of-sum-of-values/51556 "2016-06-01T12:26:14Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![bharat](https://avatars.discourse-cdn.com/v4/letter/b/5fc32e/32.png) [@bharat](https://discuss.elastic.co/u/bharat)
#### Post date: [June 1, 2016, 12:26pm UTC](https://discuss.elastic.co/t/average-wrt-time-of-sum-of-values/51556/1 "2016-06-01T12:26:14Z")

</div>

I have logs with "product name", "sales", "date", "salesman". I want the average value of sales done by all salesmen product-wise. i.e., Average(wrt time) of sum of all the sales of same product. If I use Average as the aggregator, it is giving the average sales per salesman per time, if i use Sum as aggregator, it is giving the sum of all the sales in particular time interval

---

<div class="post-metadata">

### Author: ![Khalah\_Jones\_Golden](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/khalah_jones_golden/32/7169_2.png) [@Khalah\_Jones\_Golden](https://discuss.elastic.co/u/Khalah_Jones_Golden)
#### Post date: [June 1, 2016, 1:12pm UTC](https://discuss.elastic.co/t/average-wrt-time-of-sum-of-values/51556/2 "2016-06-01T13:12:11Z")

</div>

This sounds like you need nested aggs, which kibana is very good with. I would do a terms split for the x-axis, by "product name", then i the sum of sales. You could then a filter based on salesman name.

---

<div class="post-metadata">

### Author: ![bharat](https://avatars.discourse-cdn.com/v4/letter/b/5fc32e/32.png) [@bharat](https://discuss.elastic.co/u/bharat)
#### Post date: [June 1, 2016, 1:26pm UTC](https://discuss.elastic.co/t/average-wrt-time-of-sum-of-values/51556/3 "2016-06-01T13:26:48Z")

</div>

@ Khalah\_Jones\_Golden,  
Thanks Jones, I tried in that way but it is also taking the sum of all the values in a particular interval. What I require is to take the resultant average.

Here is my situation:  
Data with 2 salesmen and Product1  
salesman1 with a sales of x1 on day1 for Product1  
salesman2 with a sales of y1 on day1 for Product1  
...  
salesman1 with a sales of x30 on day30 for Product1  
salesman2 with a sales of y30 on day30 for Product1

With an interval of week, It is giving me the o/p: (x1+y1+x2+y2+...x7+y7), (x8+y8+x9+.....x14+y14)  
Where as I require (x1+y1+x2+y2+...x7+y7)/7, (x8+y8+x9+.....x14+y14)/7.

---

<div class="post-metadata">

### Author: ![Khalah\_Jones\_Golden](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/khalah_jones_golden/32/7169_2.png) [@Khalah\_Jones\_Golden](https://discuss.elastic.co/u/Khalah_Jones_Golden)
#### Post date: [June 1, 2016, 6:31pm UTC](https://discuss.elastic.co/t/average-wrt-time-of-sum-of-values/51556/4 "2016-06-01T18:31:43Z")

</div>

you can use the average as a metric, either as a sub agg, or as the y axis.

---

<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: [July 6, 2017, 1:51pm UTC](https://discuss.elastic.co/t/average-wrt-time-of-sum-of-values/51556/5 "2017-07-06T13:51:52Z")

</div>


