# 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:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![erikg](https://avatars.discourse-cdn.com/v4/letter/e/91b2a8/32.png) [@erikg](https://discuss.elastic.co/u/erikg)\
**Post date:** [August 16, 2024, 3:43pm UTC](https://discuss.elastic.co/t/how-to-create-thresholds-in-lens/365034/1 "2024-08-16T15:43:12Z")

</div>

Hello,

I know this can be done with TVSB:

TVSB Example:  
 ![image](https://us1.discourse-cdn.com/elastic/original/3X/3/e/3efed9055f5298a4838dc67d8dce4efbd5a26485.png)

But is it possible to add thresholds to Lens:

 ![image](https://us1.discourse-cdn.com/elastic/original/3X/7/f/7fc103f30a7afc6f19ff64ee185e4fb448410a81.png)

The reason I want to use Lens over TVSB is just that in the TVSB example it considers "/" as "empty"

---

<div class="post-metadata">

**Author:** ![stephenb](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/stephenb/32/40856_2.png) [@stephenb](https://discuss.elastic.co/u/stephenb)\
**Post date:** [August 16, 2024, 5:45pm UTC](https://discuss.elastic.co/t/how-to-create-thresholds-in-lens/365034/2 "2024-08-16T17:45:36Z")

</div>

Hmmm @erikg

Looks like that is not supported but you could do something like this?

 ![Screenshot 2024-08-16 at 10.44.47 AM](https://us1.discourse-cdn.com/elastic/original/3X/2/4/2428193d9b8fccf5845b90a91d1b66e4ee2541c5.jpeg)

---

<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 )`

---

<div class="post-metadata">

**Author:** ![stephenb](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/stephenb/32/40856_2.png) [@stephenb](https://discuss.elastic.co/u/stephenb)\
**Post date:** [August 19, 2024, 2:05pm UTC](https://discuss.elastic.co/t/how-to-create-thresholds-in-lens/365034/4 "2024-08-19T14:05:35Z")

</div>

@Marco_Liberati TIL! That is awesome with the if else..
