Select to view content in your preferred language

Using Iif or When (or something else) in advanced formatting section

917
2
Jump to solution
07-23-2023 10:16 AM
dwold
by
Frequent Contributor

I need to return an icon based on an attribute value and I am not sure if I need to you when or Iif statement...or something else. I believe I need to change something in lines 3-7 but I am new to Advanced formatting with arcade. This is what I have tried:

dwold_0-1690132493468.png

 and

dwold_1-1690132548544.png

dwold_0-1690142419846.png

 

@KenBuja 

@JohannesLindner 

@MPach 

@jcarlson 

0 Kudos
1 Solution

Accepted Solutions
jcarlson
MVP Esteemed Contributor

Using When is fine, but you need a final "default value" that the function will return if none of the conditions are met.

var icon = When(
  condition1, 'this',
  condition2, 'that',
  condition3, 'the other',
  'something else'
)

 

Iif is for true/false situations, and can only return one of two values.

There's also Decode, which takes an input value and compares it against a list of other values, similar to what you're doing here. As with When, you need a final default value.

var icon = Decode(
  s,
  '#00ff00', 'green',
  '#ff0000', 'red',
  '#ffff00', 'yellow',
  'something else'
)

 

- Josh Carlson
Kendall County GIS

View solution in original post

2 Replies
jcarlson
MVP Esteemed Contributor

Using When is fine, but you need a final "default value" that the function will return if none of the conditions are met.

var icon = When(
  condition1, 'this',
  condition2, 'that',
  condition3, 'the other',
  'something else'
)

 

Iif is for true/false situations, and can only return one of two values.

There's also Decode, which takes an input value and compares it against a list of other values, similar to what you're doing here. As with When, you need a final default value.

var icon = Decode(
  s,
  '#00ff00', 'green',
  '#ff0000', 'red',
  '#ffff00', 'yellow',
  'something else'
)

 

- Josh Carlson
Kendall County GIS
dwold
by
Frequent Contributor

@jcarlson thank you for the explanation!

0 Kudos