# Kibana: Range based on count

**URL:** <https://discuss.elastic.co/t/kibana-range-based-on-count/199431>\
**Category:** Kibana\
**Created:** [September 13, 2019, 1:03pm UTC](https://discuss.elastic.co/t/kibana-range-based-on-count/199431 "2019-09-13T13:03:52Z")\
**Posts on this page:** 1\
**Showing post:** 3

<div class="post-metadata">

**Author:** ![Catherine\_Liu](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/catherine_liu/32/34294_2.png) [@Catherine\_Liu](https://discuss.elastic.co/u/Catherine_Liu)\
**Post date:** [September 13, 2019, 8:05pm UTC](https://discuss.elastic.co/t/kibana-range-based-on-count/199431/3 "2019-09-13T20:05:40Z")

</div>

@megakoresh I believe this is doable in Canvas.

I've come up with an example Canvas expression using the Kibana logs sample data set, which I think matches your use case, that plots unique hosts vs range of patches.

 ![06%20PM](https://us1.discourse-cdn.com/elastic/original/3X/f/8/f814eabdb410ddeb0dd102ff06e9101f9a1bcdd1.png)

```auto
filters
| essql 
  query="SELECT COUNT(*) as patches_applied, host FROM \"kibana_sample_data_logs\"
GROUP BY host"
| mapColumn "range" fn={
    getCell patches_applied 
    | switch case={case if={all {gte 0} {lt 2000}} then="0-2000"}
      case={case if={all {gte 2000} {lt 4000}} then="2000-4000"}
      default="4000+"
  }
| sort by="range"
| pointseries x="range" y="unique(host)"
| plot defaultStyle={seriesStyle bars=0.4} yaxis={axisConfig tickSize=1}
| render

```

This element queries ES using ES SQL and grabs the total count per unique `host`. Then we use [`mapColumn`](https://www.elastic.co/guide/en/kibana/current/canvas-function-reference.html#mapColumn_fn) to create a new `range` column that maps each total to a range using a [`switch`](https://www.elastic.co/guide/en/kibana/current/canvas-function-reference.html#switch_fn) function. Then this pipes into a [`pointseries`](https://www.elastic.co/guide/en/kibana/current/canvas-function-reference.html#pointseries_fn) function which sets your x-axis to the `range` field and the y-axis to `unique(host)` which grabs the number of unique values from the `host` field and renders as a vertical bar chart using the [`plot`](https://www.elastic.co/guide/en/kibana/current/canvas-function-reference.html#plot_fn) function.

---

_[View the full topic](https://discuss.elastic.co/t/kibana-range-based-on-count/199431)._
