Select to view content in your preferred language

Arcade Expression for value ranges

1975
2
Jump to solution
07-14-2023 08:45 AM
MarkSenne
Emerging Contributor

In need help with an arcade expression that will allow a 'pass/fail' value when an end user selects a point and whatever value that enter cause a pass/fail prompt. I currently have it setup properly when they are concerned whether or not a value is above or below a certain value but now they are wanting it to work for range values meaning if the value is between 6-9 then it would cause a pass prompt and any values outside of that would be a fail. The script below works for the greater/lesser than parameters but I'm having a hard time making it work for ranges.

var Zinc = $feature.Zinc;
if (Zinc > 0.067) {
    return Zinc + ' mg/l (Fail)'
} else if (Zinc < 0.067) {
  return Zinc + ' mg/l (Pass)'
}
 
0 Kudos
1 Solution

Accepted Solutions
JohannesLindner
MVP Frequent Contributor

To post code:

JohannesLindner_0-1689266678674.pngJohannesLindner_1-1689266693900.png

 

Your example will return null for zinc == 0.067! Also, it can be simplified like this:

var zinc = $feature.Zinc
var status = IIf(zinc > 0.067, 'Fail', 'Pass')
return `${zinc} mg/l (${status})`

 

For ranges, you just have to edit the boolean evaluation in IIf():

var zinc = $feature.Zinc
var status = IIf(zinc >= 6 && zinc <= 9, 'Pass', 'Fail')
return `${zinc} mg/l (${status})`

Have a great day!
Johannes

View solution in original post

2 Replies
JohannesLindner
MVP Frequent Contributor

To post code:

JohannesLindner_0-1689266678674.pngJohannesLindner_1-1689266693900.png

 

Your example will return null for zinc == 0.067! Also, it can be simplified like this:

var zinc = $feature.Zinc
var status = IIf(zinc > 0.067, 'Fail', 'Pass')
return `${zinc} mg/l (${status})`

 

For ranges, you just have to edit the boolean evaluation in IIf():

var zinc = $feature.Zinc
var status = IIf(zinc >= 6 && zinc <= 9, 'Pass', 'Fail')
return `${zinc} mg/l (${status})`

Have a great day!
Johannes
MarkSenne
Emerging Contributor

Thank you Johannes! This worked perfectly!

0 Kudos