# Lens - If Statements with color

**URL:** <https://discuss.elastic.co/t/lens-if-statements-with-color/366750>\
**Category:** Kibana\
**Tags:** visualisation\
**Created:** [September 18, 2024, 4:59pm UTC](https://discuss.elastic.co/t/lens-if-statements-with-color/366750 "2024-09-18T16:59: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:** [September 18, 2024, 4:59pm UTC](https://discuss.elastic.co/t/lens-if-statements-with-color/366750/1 "2024-09-18T16:59:12Z")

</div>

Hello,  
is it possible to add a condition in Lens?  
I am trying to create a visualization that will turn "red" or "green" based on the value of a keyword.

So for example, task: "running" = green , and it will show the value of "running"  
and it will change dynamically so if the value changes to "stopping", the visualization will turn red and display the value of "stopping"

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [September 18, 2024, 5:42pm UTC](https://discuss.elastic.co/t/lens-if-statements-with-color/366750/2 "2024-09-18T17:42:59Z")

</div>

Not sure that exactly answers but @VinceDS wrote a great article recently:

> **[Kibana: How to create impactful visualisations with magic formulas ? (part 1)...](https://www.elastic.co/observability-labs/blog/kibana-impactful-visualizations-with-magic-formulas-part1)**
>
> We will see how magic math formulas in the Kibana Lens editor can help to highlight high values.

---

<div class="post-metadata">

**Author:** ![VinceDS](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/vinceds/32/121923_2.png) [@VinceDS](https://discuss.elastic.co/u/VinceDS)\
**Post date:** [September 18, 2024, 7:37pm UTC](https://discuss.elastic.co/t/lens-if-statements-with-color/366750/3 "2024-09-18T19:37:10Z")

</div>

Thanks @dadoonet !  
I am currently working on part 2 which will be about ifelse() introduced in v 8.6.  
**ifelse()** simplifies how to build a red/green visualisation.  
@erikg , here is an example taken from the future part2 article :

 ![Screenshot 2024-09-18 at 21.32.01](https://us1.discourse-cdn.com/elastic/original/3X/d/d/dd987d746c5f1d0f7025c9268c268bc22369f0f1.png)

Layer 1 (% of difference with yesterday - red - decreasing):

```auto
ifelse(
 (average(taxful_total_price) - average(taxful_total_price,shift='1d'))/ average(taxful_total_price,shift='1d') >0,
 0,
  (average(taxful_total_price) - average(taxful_total_price,shift='1d'))/ average(taxful_total_price,shift='1d') 
)

```

Layer 2:

```auto
ifelse(
    (average(taxful_total_price) - average(taxful_total_price,shift='1d'))/ average(taxful_total_price,shift='1d') >0,
  (average(taxful_total_price) - average(taxful_total_price,shift='1d'))/ average(taxful_total_price,shift='1d'),
0 )

```

---

<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 19, 2024, 8:07am UTC](https://discuss.elastic.co/t/lens-if-statements-with-color/366750/4 "2024-09-19T08:07:26Z")

</div>

Since stack version 8.11 it is available the tech preview of the new Color Mapping, available on few visualizations: [[Lens] Color mapping for categorical dimensions by markov00 · Pull Request #162389 · elastic/kibana · GitHub](https://github.com/elastic/kibana/pull/162389)
