# Kibana Dashboard - Display difference between two counts

**URL:** <https://discuss.elastic.co/t/kibana-dashboard-display-difference-between-two-counts/343687>\
**Category:** Kibana\
**Tags:** dashboard, visualisation\
**Created:** [September 24, 2023, 6:19pm UTC](https://discuss.elastic.co/t/kibana-dashboard-display-difference-between-two-counts/343687 "2023-09-24T18:19:44Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![seb.sch](https://avatars.discourse-cdn.com/v4/letter/s/94ad74/32.png) [@seb.sch](https://discuss.elastic.co/u/seb.sch)\
**Post date:** [September 24, 2023, 6:19pm UTC](https://discuss.elastic.co/t/kibana-dashboard-display-difference-between-two-counts/343687/1 "2023-09-24T18:19:44Z")

</div>

Hi there,

I've been searching on anything new to this issue for the whole weekend now, but I've found only posts which are 3+ years old.

If I needed to do implement my requirement manually, I'd do the following:

```auto
GET my-index/_count
{
  "query": {
    "bool": {
      "must": [
        {
          "match": {
            "state.before": 1
          }
        },
        {
          "match": {
            "state.after": 2
          }
        }
      ]
    }
  }
}

```

This would return a count of, let's say , 10.

Then i would run the following query:

```auto
GET my-index/_count
{
  "query": {
    "bool": {
      "must": [
        {
          "match": {
            "state.before": 2
          }
        },
        {
          "match": {
            "state.after": 3
          }
        }
      ]
    }
  }
}

```

This would return, let's say, 8.

Now I would calculate 10 - 8 = 2. And I would like to display this difference, i.e. the 2, as a number in a Kibana dashboard. Is that possible? And if so, what is the least expensive way in terms of consumption of CPU, RAM, etc.?

Thanks in advance!

---

<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:** [September 25, 2023, 8:56am UTC](https://discuss.elastic.co/t/kibana-dashboard-display-difference-between-two-counts/343687/2 "2023-09-25T08:56:29Z")

</div>

Hi @seb.sch

have you tried already a Lens Metric with a formula like this?

```auto
count(kql='state.before: 1 AND state.after: 2') - count(kql='state.before: 2 AND state.after: 3')

```

---

<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:** [October 23, 2023, 8:56am UTC](https://discuss.elastic.co/t/kibana-dashboard-display-difference-between-two-counts/343687/3 "2023-10-23T08:56:58Z")

</div>

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