# How to divide and visualize two aggregated data？

**URL:** <https://discuss.elastic.co/t/how-to-divide-and-visualize-two-aggregated-data/292758>\
**Category:** Kibana\
**Tags:** canvas\
**Created:** [December 23, 2021, 3:52am UTC](https://discuss.elastic.co/t/how-to-divide-and-visualize-two-aggregated-data/292758 "2021-12-23T03:52:51Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![wsysx123](https://avatars.discourse-cdn.com/v4/letter/w/b3f665/32.png) [@wsysx123](https://discuss.elastic.co/u/wsysx123)\
**Post date:** [December 23, 2021, 3:52am UTC](https://discuss.elastic.co/t/how-to-divide-and-visualize-two-aggregated-data/292758/1 "2021-12-23T03:52:51Z")

</div>

As a beginner of Kibana, I feel very powerful. However, there is a problem that cannot be realized at present, so I hereby ask for advice.  
Suppose I have two fields, named 'key1' and 'key2', and aggregation them by 1 minute.  
first,i want to aggregation them.sum(key1.data) and sum(key2.data)  
and then the Calculate division value Such as sum(key1.data)/sum(key2.data)  
then visualize the data by interval of 1 minute.

This is very useful in the scenario of statistic global average speed, I hope someone can help me solve it, thank you!

---

<div class="post-metadata">

**Author:** ![AquaX](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/aquax/32/92006_2.png) [@AquaX](https://discuss.elastic.co/u/AquaX)\
**Post date:** [December 23, 2021, 3:12pm UTC](https://discuss.elastic.co/t/how-to-divide-and-visualize-two-aggregated-data/292758/2 "2021-12-23T15:12:47Z")

</div>

Create a [Transformation](https://www.elastic.co/guide/en/elasticsearch/reference/current/transform-overview.html) in Kibana and then use the transformation index as your visualization data source 🙂

---

<div class="post-metadata">

**Author:** ![Tomo\_M](https://avatars.discourse-cdn.com/v4/letter/t/848f3c/32.png) [@Tomo\_M](https://discuss.elastic.co/u/Tomo_M)\
**Post date:** [December 24, 2021, 11:06am UTC](https://discuss.elastic.co/t/how-to-divide-and-visualize-two-aggregated-data/292758/3 "2021-12-24T11:06:49Z")

</div>

Other possible options may be

- using [vega-lite calculate transform](https://vega.github.io/vega-lite/docs/calculate.html) with customized visualization in kibana
- using [Scripted metric aggregation](https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-metrics-scripted-metric-aggregation.html)

although I haven't actually tried them.

---

<div class="post-metadata">

**Author:** ![wsysx123](https://avatars.discourse-cdn.com/v4/letter/w/b3f665/32.png) [@wsysx123](https://discuss.elastic.co/u/wsysx123)\
**Post date:** [December 24, 2021, 12:34pm UTC](https://discuss.elastic.co/t/how-to-divide-and-visualize-two-aggregated-data/292758/5 "2021-12-24T12:34:48Z")

</div>

Thanks to everyone above, I have solved this problem by using Timelion graph drawing, the syntax is:

.es(index=mylog-_,timefield=@timestamp,metric=sum:key1).divide(.es(index=mylog-_,timefield=@timestamp,metric=sum:key2)).label('speed' )

So you can calculate the overall speed!

---

<div class="post-metadata">

**Author:** ![Tomo\_M](https://avatars.discourse-cdn.com/v4/letter/t/848f3c/32.png) [@Tomo\_M](https://discuss.elastic.co/u/Tomo_M)\
**Post date:** [December 24, 2021, 3:50pm UTC](https://discuss.elastic.co/t/how-to-divide-and-visualize-two-aggregated-data/292758/6 "2021-12-24T15:50:25Z")

</div>

Thank you for sharing an elegant solution!

---

<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:** [January 21, 2022, 3:50pm UTC](https://discuss.elastic.co/t/how-to-divide-and-visualize-two-aggregated-data/292758/7 "2022-01-21T15:50:29Z")

</div>

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