# Combine two different aggregation results into one

**URL:** https://discuss.elastic.co/t/combine-two-different-aggregation-results-into-one/307143
**Category:** Kibana
**Created:** [June 14, 2022, 11:25am UTC](https://discuss.elastic.co/t/combine-two-different-aggregation-results-into-one/307143 "2022-06-14T11:25:21Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![shi](https://avatars.discourse-cdn.com/v4/letter/s/f14d63/32.png) [@shi](https://discuss.elastic.co/u/shi)
#### Post date: [June 14, 2022, 11:25am UTC](https://discuss.elastic.co/t/combine-two-different-aggregation-results-into-one/307143/1 "2022-06-14T11:25:21Z")

</div>

We have traffic logs from and to WAN. We need to 🙂

1. We need to add/aggregate the _sentbytes_ when the _source interface is WAN._
2. We need to add/aggregate the _receivedbytes_ when the _destination interface is WAN._
3. We need to find the sum of above two aggregations.

How to do this?  
E.g.

```auto
@timestamp action utmaction srcip srccountry	srcintf	srcport dstip dstcountry dstintf	dstport	service	sentbyte	rcvdbyte

Jun 14, 2022 @ 16:37:11.866	close	- 164.xxx.xxx.xxx	India WAN 48012	210.xxx.xxx.xxx	India LAN 443 HTTPS 879 2890

Jun 14, 2022 @ 16:37:11.746	close	- 10.xxx.xxx.xxx Reserved	LAN 53316	164.xxx.xxx.xxx	India WAN 443 HTTPS 2010 1549

Jun 14, 2022 @ 16:37:05.925	close	- 172.xxx.xxx.xxx	Reserved	LAN 34674	104.16.219.84	United States WAN 443 HTTPS 1212 4088

1: 879
2: 1549+4088 = 5637
3: Here the answer should be 879+5637 = 6516

```

We could do Step 1 and 2 independently. How can we combine the results of these aggregations together as required in step 3 (sum)

Thanks and Regards  
Shi

---

<div class="post-metadata">

### Author: ![Stratoula\_Kalafateli](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/stratoula_kalafateli/32/70923_2.png) [@Stratoula\_Kalafateli](https://discuss.elastic.co/u/Stratoula_Kalafateli)
#### Post date: [June 14, 2022, 11:44am UTC](https://discuss.elastic.co/t/combine-two-different-aggregation-results-into-one/307143/2 "2022-06-14T11:44:32Z")

</div>

You could use Lens formula and do something like this

```auto
average(bytes, kql='geo.dest : "AM"') + average(bytes, kql='geo.dest : "AO"')

```

where in average you can add the aggregation you want

Here is a metric visualization with a formula in Lens

 ![image](https://us1.discourse-cdn.com/elastic/original/3X/f/5/f5712e787d93731052ead016644c0f045d980c27.jpeg)

---

<div class="post-metadata">

### Author: ![shi](https://avatars.discourse-cdn.com/v4/letter/s/f14d63/32.png) [@shi](https://discuss.elastic.co/u/shi)
#### Post date: [June 16, 2022, 6:00pm UTC](https://discuss.elastic.co/t/combine-two-different-aggregation-results-into-one/307143/3 "2022-06-16T18:00:19Z")

</div>

thanks a lot  
it worked  
thanks and regards  
shini

---

<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 14, 2022, 6:00pm UTC](https://discuss.elastic.co/t/combine-two-different-aggregation-results-into-one/307143/4 "2022-07-14T18:00:28Z")

</div>

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