Select to view content in your preferred language

Arcade Expression "if/then" statement

12279
3
Jump to solution
07-22-2019 01:43 PM
AndyBohnhoff
Emerging Contributor

I am looking to create an expression in Arcade using multiple "if/then" statements. The issue I am running into is trying to use "AND" in between statements. I currently have a flag if the bench is identical or not. It looks like this:

if ($feature.toe_target_caps==
$feature.target_formation) {return 1}
else {return 0}

What I need to do next is say

if target_formation = "NIOBRARA A" and toe_target_caps = "NIOBRARA B" = 2

if target_formation = "NIOBRARA B" and toe_target_caps = "NIOBRARA C" = 3

if target_formation = "NIOBRARA A" and toe_target_caps = "NIOBRARA C" = 4

else {return 0}

So ideally I would have flags 5 flags (0-4). Thanks!

target picture

0 Kudos
1 Solution

Accepted Solutions
LanceCole
MVP Regular Contributor

Andy,

You can try the following samples but there are a few holes in the logic from the sample you provided.  For example "NIOBRARA A" and "CODELL", "NIOBRARA B" and "CODELL", "NIOBRARA B" and "NIOBRARA A", "CODELL" and "NIOBRARA A", etc. will all result in a return of 0.  Is this what you wanted? If not, you can expand the conditional statements to include these as well.  The first example use && for (and) and if was need || for (or).

if ($feature.target_formation == $feature.toe_target_caps){return 1}
if ($feature.target_formation == "NIOBRARA A" && $feature.toe_target_caps == "NIOBRARA B") {return 2}
if ($feature.target_formation == "NIOBRARA B" && $feature.toe_target_caps == "NIOBRARA C" ) {return 3}
if ($feature.target_formation == "NIOBRARA A" && $feature.toe_target_caps == "NIOBRARA C"){return 4}
else {return 0}‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

This second example has the same output but is based upon grouped and nested conditional statements

if ($feature.target_formation == $feature.toe_target_caps){
  return 1
}
if ($feature.target_formation == "NIOBRARA A"){
  if ($feature.toe_target_caps == "NIOBRARA B") {
    return 2
  }
  else if ($feature.toe_target_caps == "NIOBRARA C" ) {
    return 4
  }
}
if ($feature.target_formation == "NIOBRARA B"){
  if ($feature.toe_target_caps == "NIOBRARA C") {
    return 3
  }
}
else {return 0}
 ‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

View solution in original post

3 Replies
LanceCole
MVP Regular Contributor

Andy,

You can try the following samples but there are a few holes in the logic from the sample you provided.  For example "NIOBRARA A" and "CODELL", "NIOBRARA B" and "CODELL", "NIOBRARA B" and "NIOBRARA A", "CODELL" and "NIOBRARA A", etc. will all result in a return of 0.  Is this what you wanted? If not, you can expand the conditional statements to include these as well.  The first example use && for (and) and if was need || for (or).

if ($feature.target_formation == $feature.toe_target_caps){return 1}
if ($feature.target_formation == "NIOBRARA A" && $feature.toe_target_caps == "NIOBRARA B") {return 2}
if ($feature.target_formation == "NIOBRARA B" && $feature.toe_target_caps == "NIOBRARA C" ) {return 3}
if ($feature.target_formation == "NIOBRARA A" && $feature.toe_target_caps == "NIOBRARA C"){return 4}
else {return 0}‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

This second example has the same output but is based upon grouped and nested conditional statements

if ($feature.target_formation == $feature.toe_target_caps){
  return 1
}
if ($feature.target_formation == "NIOBRARA A"){
  if ($feature.toe_target_caps == "NIOBRARA B") {
    return 2
  }
  else if ($feature.toe_target_caps == "NIOBRARA C" ) {
    return 4
  }
}
if ($feature.target_formation == "NIOBRARA B"){
  if ($feature.toe_target_caps == "NIOBRARA C") {
    return 3
  }
}
else {return 0}
 ‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍
AndyBohnhoff
Emerging Contributor

That worked great, thank you Lance!

0 Kudos
LanceCole
MVP Regular Contributor

I am glad that worked. 

0 Kudos