# Weighted avg aggregation in lens

**URL:** <https://discuss.elastic.co/t/weighted-avg-aggregation-in-lens/310652>\
**Category:** Kibana\
**Tags:** lens\
**Created:** [July 26, 2022, 2:14pm UTC](https://discuss.elastic.co/t/weighted-avg-aggregation-in-lens/310652 "2022-07-26T14:14:11Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![tobi](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/tobi/32/78397_2.png) [@tobi](https://discuss.elastic.co/u/tobi)\
**Post date:** [July 26, 2022, 2:14pm UTC](https://discuss.elastic.co/t/weighted-avg-aggregation-in-lens/310652/1 "2022-07-26T14:14:12Z")

</div>

Hi together,

I currently have an request to implement via lens visualization.  
We have a weighted field as runtime field (rate \* traffic.count).  
We want to use that field to calcuate a weighted rate with the sum of all traffic in a given timeframe.  
It seems that this is possible via Elasticsearch itself [Weighted avg aggregation | Elasticsearch Guide [8.3] | Elastic](https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-metrics-weight-avg-aggregation.html) but not via Lens visualization.  
Or do miss anyhting?  
A math formular calculation like sum(rate.weighted) / overall\_sum(sum(traffic.count)) does not lead to the expected result.  
Any advice on this ?

---

<div class="post-metadata">

**Author:** ![flash1293](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/flash1293/32/41227_2.png) [@flash1293](https://discuss.elastic.co/u/flash1293)\
**Post date:** [July 26, 2022, 3:39pm UTC](https://discuss.elastic.co/t/weighted-avg-aggregation-in-lens/310652/2 "2022-07-26T15:39:55Z")

</div>

I assume `rate.weighted` is the `rate * traffic.count` runtime field?

In that case, `sum(rate.weighted) / sum(traffic.count)` should do the trick

---

<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:** [August 23, 2022, 3:40pm UTC](https://discuss.elastic.co/t/weighted-avg-aggregation-in-lens/310652/3 "2022-08-23T15:40:03Z")

</div>

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