# How to filter field with count in datatable

**URL:** <https://discuss.elastic.co/t/how-to-filter-field-with-count-in-datatable/257462>\
**Category:** Kibana\
**Created:** [December 3, 2020, 7:16am UTC](https://discuss.elastic.co/t/how-to-filter-field-with-count-in-datatable/257462 "2020-12-03T07:16:25Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![tungpzostar](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/tungpzostar/32/72181_2.png) [@tungpzostar](https://discuss.elastic.co/u/tungpzostar)\
**Post date:** [December 3, 2020, 7:16am UTC](https://discuss.elastic.co/t/how-to-filter-field-with-count-in-datatable/257462/1 "2020-12-03T07:16:25Z")

</div>

I have field state which has 2 values "BEGIN" and "END", I want to show count when state is "BEGIN" so I've tried

```auto
{
  "query": {
    "match_phrase": {
      "state": "BEGIN"
    }
  }
}

```

but nothing works, any idea how to do this. Thanks 😃  
 ![image](https://us1.discourse-cdn.com/elastic/original/3X/e/b/ebb8b14e299c98846533c57bb759330f88809583.png)

---

<div class="post-metadata">

**Author:** ![dosant](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dosant/32/64489_2.png) [@dosant](https://discuss.elastic.co/u/dosant)\
**Post date:** [December 3, 2020, 1:11pm UTC](https://discuss.elastic.co/t/how-to-filter-field-with-count-in-datatable/257462/2 "2020-12-03T13:11:33Z")

</div>

Hi @tungpzostar,

I'd first create a viz that shows count for all states (just leave metric configuration as you've showed on a screenshot) and then I'd use filter bar to filter only by `state:begin`:

![Screenshot 2020-12-03 at 14.09.12](https://us1.discourse-cdn.com/elastic/original/3X/1/9/199c05f144cd8d50812f9e0fb3329dda2bae5ef3.png) ![Screenshot 2020-12-03 at 14.09.19](https://us1.discourse-cdn.com/elastic/original/3X/4/d/4d52358af42f4e001d7b44c7c0073fde6c2e07f8.png)

If you'd do similar to my example, you'd I just have `state: BEGIN/END` instead of mine `cancelled: true/false`

---

<div class="post-metadata">

**Author:** ![tungpzostar](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/tungpzostar/32/72181_2.png) [@tungpzostar](https://discuss.elastic.co/u/tungpzostar)\
**Post date:** [December 4, 2020, 4:25am UTC](https://discuss.elastic.co/t/how-to-filter-field-with-count-in-datatable/257462/3 "2020-12-04T04:25:47Z")

</div>

I can filter out state: BEGIN but can I do count BEGIN, count END in one data table. Thanks 😃

---

<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 1, 2021, 4:26am UTC](https://discuss.elastic.co/t/how-to-filter-field-with-count-in-datatable/257462/4 "2021-01-01T04:26:04Z")

</div>

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