Select to view content in your preferred language

Arcade IF statements with AND or OR

51375
8
Jump to solution
07-23-2018 12:45 PM
by Anonymous User
Not applicable

I've searched and searched but either couldn't figure out how to word my question or it hasn't been asked. Basically, is it possible to use AND or OR in an IF statement so I don't have to make a bunch of expressions? Especially useful when it comes to pop-ups.

Example (very generalized):

I want to display a pop-up that shows one of three things; A, AB, or None. Naturally I would think of it like a definition query,

= IIf($feature["OCC_ELUM"] == 0, " ", "A")

OR

= IIf($feature["OCC_ELUM"] == 1, " ", "AB")

OR

= IIf($feature["OCC_ELUM"] == 2, " ", "None")

But this isn't the case. Any help?

0 Kudos
1 Solution

Accepted Solutions
CarmelConnolly
Esri Regular Contributor

Hi Bryan, 

Something like this might work:

if ( $feature["OCC_ELUM"] == 0) {
return "A"
}
else if ( $feature["OCC_ELUM"] == 1) {
return "AB"
}
else if ( $feature["OCC_ELUM"] == 2) {
return "None"
}

You can add in as many 'else if's as needed. If you needed, you could finish it with 'else' to catch any other values

if ( $feature["OCC_ELUM"] == 0) {
return "A"
}
else if ( $feature["OCC_ELUM"] == 1) {
return "AB"
}
else if ( $feature["OCC_ELUM"] == 2) {
return "None"
}

else {

return "No Values"

}

Carmel

View solution in original post

8 Replies
CarmelConnolly
Esri Regular Contributor

Hi Bryan, 

Something like this might work:

if ( $feature["OCC_ELUM"] == 0) {
return "A"
}
else if ( $feature["OCC_ELUM"] == 1) {
return "AB"
}
else if ( $feature["OCC_ELUM"] == 2) {
return "None"
}

You can add in as many 'else if's as needed. If you needed, you could finish it with 'else' to catch any other values

if ( $feature["OCC_ELUM"] == 0) {
return "A"
}
else if ( $feature["OCC_ELUM"] == 1) {
return "AB"
}
else if ( $feature["OCC_ELUM"] == 2) {
return "None"
}

else {

return "No Values"

}

Carmel

DavidAllen
Frequent Contributor

Or use Decode()

Decode($feature.OCC_ELUM,1,"AB",2,"None","No Values")

by Anonymous User
Not applicable

Hi, this article helped to solve a big problem and many thanks. How can we replace '_' that contains in values of a field with space?

Wali

0 Kudos
XanderBakker
Esri Esteemed Contributor

Hi Sayed Wali ,

I you want to replace "_" by " " you can use the function Replace. Something like this:

var result = Replace(YourText, "_", " ");
BrandonBiron
Occasional Contributor

The best way to use AND in Arcade is the following: "&&" input && between the expressions like the following example:

If (($feature.GlobalID != Null) && ($feature.TYPE == "Conduit")){
Return "CONDUIT::" + Upper(right(split($feature.GLOBALID,"-")[0],8))
}

The above is a script that looks at data from two fields and returns a unique ID for an element based on the entries of that Field. 

VanessaSimps
Frequent Contributor

How would this work if I have two different fields that can signify the same thing? 

Here is what I am trying to show: 

  • Smoked -

    • Smoke = True OR Connected to Sanitary = True

      • DomainName($feature,"test_type") == 'Smoke Test'
      • DomainName($feature,"other_testresult")=='Connected to Sanitary'
  • Smoked w/ Problems

    • Smoked with Problems = True OR No Show = True

      • DomainName($feature,"smoke_result") == 'Smoke with Problems'
      • DomainName($feature,"other_testresult")=='No Show'
  • Test Failed

    • (No Smoke = True AND (SmokeProblem <> Vacant Lot OR SmokeProblem <> Parking Lot)) OR Connected to Storm = True

      • DomainName($feature,"smoke_result")=='No Smoke'
      • $feature["vacant_lot"] == 0
      • $feature["parking_lot"] == 0
  • Septic

    • Septic = True

      • DomainName($feature,"test_type") == 'Septic System'
  • Vacant/Parking Lot

    • SmokeProblem <> Vacant Lot OR SmokeProblem <> Parking Lot

      • $feature["vacant_lot"] == 1
      • $feature["parking_lot"] == 1

 

 

//Smoked
if ( DomainName($feature,"test_type") == 'Smoke Test') 
{
if ( DomainName($feature,"other_testresult")=='Connected to Sanitary')
{
return "Smoked"
}
}
//Septic
else if ( DomainName($feature,"test_type") == 'Septic System')
{
return "Septic"
}
//Smoked with Problems
else if ( DomainName($feature,"smoke_result") == 'Smoke with Problems') 
{
if (DomainName($feature,"other_testresult")=='No Show')
{
return "Smoked with Problems"
}
}
//Test Failed
else if (DomainName($feature,"smoke_result")=='No Smoke')
{
if ( $feature["vacant_lot"] == 0) 
{
if ( $feature["parking_lot"] == 0)
{
return "Test Failed"
}
}
}
//Vacant/Parking Lot
else if ( $feature["vacant_lot"] == 1) 
{
if ( $feature["parking_lot"] == 1) 
{
return "Vacant/Parking Lot"
}
}
else {

return "No Values"

}

 

Here is what I have come up with so far, but it is only returning "No Values" . I think this has to do with the fact that I am trying to get two different fields to = the same thing. Has anyone done this before that can help me out? 

Thank you in advance,

Vanessa

rich6626
New Contributor

There is a technical article on this subject in the Esri Knowledge Base: How To: Use multiple Arcade IF statements in ArcGIS Online

0 Kudos
ChristianCordova
Emerging Contributor

Use && for AND conditions, use || for OR conditions. For instance you can use an expression like this in Arcade (OR): 

 

if ($feature.evaluation_type == "01" || isEmpty($feature.evaluation_type)) {
       return 0;
 }

 

 
0 Kudos