# How to create thresholds in Lens

**URL:** <https://discuss.elastic.co/t/how-to-create-thresholds-in-lens/365034>\
**Category:** Kibana\
**Tags:** visualisation\
**Created:** [August 16, 2024, 3:43pm UTC](https://discuss.elastic.co/t/how-to-create-thresholds-in-lens/365034 "2024-08-16T15:43:12Z")\
**Posts on this page:** 1\
**Showing post:** 3

<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 19, 2024, 9:44am UTC](https://discuss.elastic.co/t/how-to-create-thresholds-in-lens/365034/3 "2024-08-19T09:44:04Z")

</div>

There are 3 possible outcome to represent a chart with a threshold over it:

- show all bars the same way + add a threshold line
- show the bars below the threshold with color X and the ones above with color Y (like TSVB)
- show all bars below the threshold with color X and the part over the threshold with color Y

Let's go in order.

### Show all bars the same way + add a threshold line

This is the simplest solution: create a chart and then add a reference line layer and configure the threshold.

 ![Screenshot 2024-08-19 at 10.19.04](https://us1.discourse-cdn.com/elastic/original/3X/b/4/b443ca6561aac18aac02986c3782300a41ea5e41.png)

Now let's see the other two options, who require a combination of a stack chart type and the definition of multiple metrics per layer

# show the bars below the threshold with color X and the ones above with color Y

This hack leverages the stacked nature of the chart, and it applies the threshold at the metric level.

 ![Screenshot 2024-08-19 at 11.30.09](https://us1.discourse-cdn.com/elastic/original/3X/6/2/62c0414b106ca59ff2f7aea0a9c24d64b68d18a6.png)

In the pic above it is possible to see the 2 metrics defined: one for the metric below and another above the threshold.  
Both metric have a formula with an `ifelse` but the 2nd and 3rd arguments are respectively swapped:

- Below threshold formula: `ifelse( metric() >= THRESHOLD, 0, metric() )`
- Above threshold formula: `ifelse( metric() >= THRESHOLD, metric(), 0 )`

For instance in the pic above this is the below formula: `ifelse( count() >= 150, 0, count() )`

# show all bars below the threshold with color X and the part over the threshold with color Y

This is an evolution from the version above, I've seen it used from @VinceDS , and this is a nice trick to visualize only the portion above the threshold.

 ![Screenshot 2024-08-19 at 11.41.04](https://us1.discourse-cdn.com/elastic/original/3X/f/e/fefb0118209e59661a73793b459df1d5087a1c6b.png)

This time formulas as slightly different from the ones above as it needs to subtract the threshold values from the metric one:

- Below threshold formula: `ifelse( metric() >= THRESHOLD, THRESHOLD, metric() - THRESHOLD)`
- Above threshold formula: `ifelse( metric() >= THRESHOLD, metric() - THRESHOLD, 0 )`

---

_[View the full topic](https://discuss.elastic.co/t/how-to-create-thresholds-in-lens/365034)._
