# Metric count aggregation difference

**URL:** <https://discuss.elastic.co/t/metric-count-aggregation-difference/282575>\
**Category:** Kibana\
**Created:** [August 26, 2021, 12:30pm UTC](https://discuss.elastic.co/t/metric-count-aggregation-difference/282575 "2021-08-26T12:30:30Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![gijo](https://avatars.discourse-cdn.com/v4/letter/g/59ef9b/32.png) [@gijo](https://discuss.elastic.co/u/gijo)\
**Post date:** [August 26, 2021, 12:30pm UTC](https://discuss.elastic.co/t/metric-count-aggregation-difference/282575/1 "2021-08-26T12:30:30Z")

</div>

I have a index with source field. It can have two values. For ex: "sourceA" & "sourceB".  
I am trying to create to metric aggregation panels with source filter.  
It is possible to create metric aggregation with single filter source : "source A" or "source B" and get the respective count of documents.

However  
I want to create a metric aggregation visualization with difference in the count of documents with souce A and source B.  
Could you please help?

---

<div class="post-metadata">

**Author:** ![Marco\_Liberati](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/marco_liberati/32/82953_2.png) [@Marco\_Liberati](https://discuss.elastic.co/u/Marco_Liberati)\
**Post date:** [August 26, 2021, 3:27pm UTC](https://discuss.elastic.co/t/metric-count-aggregation-difference/282575/2 "2021-08-26T15:27:53Z")

</div>

Hi @gijo ,

welcome to the Kibana community.

> I want to create a metric aggregation visualization with difference in the count of documents with souce A and source B.

If I understood correctly your request, I think Lens [new formula](https://www.elastic.co/guide/en/kibana/master/lens.html) feature can be useful.

If `sourceA` and `sourceB` are mutually exclusive probably you can do something like:

```auto
count(kql='sourceA: *') - count(kql='sourceB: *')

```

---

<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:** [September 23, 2021, 3:28pm UTC](https://discuss.elastic.co/t/metric-count-aggregation-difference/282575/3 "2021-09-23T15:28:13Z")

</div>

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