# Several if()s inside coalesce() for Vision - alternatives?

**URL:** <https://forum.inductiveautomation.com/t/several-if-s-inside-coalesce-for-vision-alternatives/41657>\
**Category:** Ignition\
**Tags:** ignition79\
**Created:** [December 18, 2020, 6:50pm UTC](https://forum.inductiveautomation.com/t/several-if-s-inside-coalesce-for-vision-alternatives/41657 "2020-12-18T18:50:06Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![filipg](https://avatars.discourse-cdn.com/v4/letter/f/a88e4f/32.png) [@filipg](https://forum.inductiveautomation.com/u/filipg)\
**Post date:** [December 18, 2020, 6:50pm UTC](https://forum.inductiveautomation.com/t/several-if-s-inside-coalesce-for-vision-alternatives/41657/1 "2020-12-18T18:50:06Z")

</div>

So, apparently I need to logically write out my question for this group to answer my own question. Who knew posting here would be so therapeutic?!

Original Q: I’m trying to make it more obvious for operators which asset(s) are contributing to an alarm by highlighting them on main screen that shows an overview of the process. I’ve used if()s nested inside a concat() before for handling strings, but I’m getting warnings with toColor() of the kind, “Cannot coerce string value ‘nullnullnullnull’ into a color”

This was the offending code:

```auto
// Expression to turn background of button depending on alarm severity
if ({Chiller_Is_Active},
  concat (
  	if ({Condition1},
  		toColor("Orange"),NULL),
	if ({Condition2},
		toColor("White"),NULL),
	if (Condition3},
		toColor("Yellow"),NULL),
	if (Condition4},
		toColor("Red"),NULL)	
  ),
  	toColor("White") // Default
)

```

Then I realized I was after the coalesce() function and I just needed to switch the colors names themselves

```auto
// Expression to turn background of button depending on alarm severity
toColor(
    coalesce(
        if ({Chiller_Is_Active},"White",NULL), // default, unless alarm
        if ({Condition1},"Orange",NULL), // bad
        if ({Condition2},"White",NULL), // okay for our purposes
        if (Condition3},"Yellow",NULL), // suspicious
        if (Condition4},"Red",NULL) // awful
    )//coalesce (not concat, you nincompoop!)
)//toColor

```

Are there better ways to do accomplish same effect?

---

<div class="post-metadata">

**Author:** ![JordanCClark](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jordancclark/32/83362_2.png) [@JordanCClark](https://forum.inductiveautomation.com/u/JordanCClark)\
**Post date:** [December 18, 2020, 7:03pm UTC](https://forum.inductiveautomation.com/t/several-if-s-inside-coalesce-for-vision-alternatives/41657/2 "2020-12-18T19:03:19Z")

</div>

I would wrap the conditions in a binEnc expression bound to a custom property (I usually use one called ‘state’, then use the Style Customizer to affect the look of the button.

---

<div class="post-metadata">

**Author:** ![JordanCClark](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jordancclark/32/83362_2.png) [@JordanCClark](https://forum.inductiveautomation.com/u/JordanCClark)\
**Post date:** [December 18, 2020, 7:07pm UTC](https://forum.inductiveautomation.com/t/several-if-s-inside-coalesce-for-vision-alternatives/41657/3 "2020-12-18T19:07:08Z")

</div>

Sorry, I should add that the Style customize can affect text as well. 😉

---

<div class="post-metadata">

**Author:** ![filipg](https://avatars.discourse-cdn.com/v4/letter/f/a88e4f/32.png) [@filipg](https://forum.inductiveautomation.com/u/filipg)\
**Post date:** [December 18, 2020, 7:27pm UTC](https://forum.inductiveautomation.com/t/several-if-s-inside-coalesce-for-vision-alternatives/41657/4 "2020-12-18T19:27:01Z")

</div>

Can you show me a short sample of what you mean? Doesn’t have to run. Thank you.

(I schedule ignition work once a week for force myself to maintain some basic proficiency…)

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [December 18, 2020, 7:54pm UTC](https://forum.inductiveautomation.com/t/several-if-s-inside-coalesce-for-vision-alternatives/41657/5 "2020-12-18T19:54:43Z")

</div>

`binEnc/binEnum` take a sequence of booleans and turn them into an integer value. That integer is well suited for use with the [Style Customizer](https://docs.inductiveautomation.com/display/DOC81/Vision+Component+Customizers#VisionComponentCustomizers-StyleCustomizer)

So `binEnum(false, false, true, false, true)` would evaluate to `3` - the third argument in sequence is true - while `binEnc(false, false, true, false, true)` constructs a binary number (`00101`) so the output is 5. (I may have gotten the order incorrect, but that’s the idea, regardless) `binEnum` is useful for mutually exclusive conditions, `binEnc` is useful for potentially complementary conditions.

So the idea is you create a custom property, add your conditions inside `binEnc` or `binEnum`, and then use the style customizer to drive the appearance off that custom property. That has the (in my opinion) advantage of separating the logic from the actual styles - and the customizer allows you to change multiple properties at once, as Jordan mentioned.

---

<div class="post-metadata">

**Author:** ![JordanCClark](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jordancclark/32/83362_2.png) [@JordanCClark](https://forum.inductiveautomation.com/u/JordanCClark)\
**Post date:** [December 18, 2020, 7:58pm UTC](https://forum.inductiveautomation.com/t/several-if-s-inside-coalesce-for-vision-alternatives/41657/6 "2020-12-18T19:58:34Z")

</div>

Doesn’t have to run?!? Where’s the fun in that? 🤪

Here’s a window to illustrate.

[JC\_Style\_Customizer\_Example.proj](https://forum.inductiveautomation.com/uploads/short-url/3934A8zyCN8Z34BYm23NG8GMy2e.proj) (7.7 KB)

---

<div class="post-metadata">

**Author:** ![nminchin](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/nminchin/32/6911_2.png) [@nminchin](https://forum.inductiveautomation.com/u/nminchin)\
**Post date:** [December 18, 2020, 8:26pm UTC](https://forum.inductiveautomation.com/t/several-if-s-inside-coalesce-for-vision-alternatives/41657/7 "2020-12-18T20:26:22Z")

</div>

But then, using a style customiser forces you to use magic colours…

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [December 18, 2020, 9:21pm UTC](https://forum.inductiveautomation.com/t/several-if-s-inside-coalesce-for-vision-alternatives/41657/8 "2020-12-18T21:21:12Z")

</div>

Not if you cell update bind the styles dataset…

---

<div class="post-metadata">

**Author:** ![nminchin](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/nminchin/32/6911_2.png) [@nminchin](https://forum.inductiveautomation.com/u/nminchin)\
**Post date:** [December 19, 2020, 3:08am UTC](https://forum.inductiveautomation.com/t/several-if-s-inside-coalesce-for-vision-alternatives/41657/9 "2020-12-19T03:08:34Z")

</div>

Huh, I’d never thought of that! 🤔
