Arcade help, two field symbology

322
4
Jump to solution
03-18-2024 07:26 AM
JayHodny
Occasional Contributor III

Hello!  My Arcade skills are not strong yet.  I am trying to write an expression to symbolize on two criteria:  1) water meter sizes less than or equal to 1.0 inch having an installation date of up to 15 years old, and, 2) water meter sizes greater than or equal to 1.5 inches having an installation date of up to 10 years old.  If I comment out all of the code after the first return: return "Small Meters installed up to 15 years ago" } the code runs and produces results.  When I remove the comments and try to get the entire code to run, I get an Invalid Expression, Error on line 12, Reserved keyword used.  I have tried multiple ideas, but no further progress.  Any help would be greatly appreciated.  Many thanks in advance.

 

//Meters less than or equal to 1.0 inches and installed less than or equal to 15 years ago

if ($feature.metersize_inches <= '1.0')

if (DateDiff(Now(), Date($feature.installdt), 'year') <= 15)
{
return "Small Meters installed up to 15 years ago" }

//Meters greater than or equal to 1.5 inches and installed less than or equal to 10 years ago
else if ($feature.metersize_inches >= '1.5')

else if (DateDiff(Now(), Date($feature.installdt), 'year') <= 10)
{
return "Large Meters installed up to 10 years ago" }

//Time since meter installation is none of these
else {
return "None of these" }

0 Kudos
2 Solutions

Accepted Solutions
jcarlson
MVP Esteemed Contributor

On line 10, you have an else if that isn't followed by a {…} of any kind. You need to combine your conditions into a single statement, you can't just put two "else if" statements back to back.

Same goes for the first set of if statements. Try combining your conditions like this:

 

//Meters less than or equal to 1.0 inches and installed less than or equal to 15 years ago
if (($feature.metersize_inches <= '1.0') && (DateDiff(Now(), Date($feature.installdt), 'year') <= 15)) {
  return "Small Meters installed up to 15 years ago"
}

//Meters greater than or equal to 1.5 inches and installed less than or equal to 10 years ago
else if (($feature.metersize_inches >= '1.5') && (DateDiff(Now(), Date($feature.installdt), 'year') <= 10)) {
  return "Large Meters installed up to 10 years ago"
}

//Time since meter installation is none of these
else {
  return "None of these"
}

Edit: conditions should be AND (&&) not IF.

 

- Josh Carlson
Kendall County GIS

View solution in original post

0 Kudos
KenBuja
MVP Esteemed Contributor

There were a couple of issues. First, you were using a string ('1.0') instead of a number to check for metersize_inches. Also, you were missing some curly braces in the if statements.

If I understand your logic, then this should work using the When function.

When (//Meters less than or equal to 1.0 inches and installed less than or equal to 15 years ago
      $feature.metersize_inches <= 1.0 && DateDiff(Now(), Date($feature.installdt), 'year') <= 15, "Small Meters installed up to 15 years ago",
      //Meters greater than or equal to 1.5 inches and installed less than or equal to 10 years ago
      $feature.metersize_inches >= 1.5 && DateDiff(Now(), Date($feature.installdt), 'year') <= 10, "Large Meters installed up to 10 years ago",
      "None of these");

 

View solution in original post

0 Kudos
4 Replies
jcarlson
MVP Esteemed Contributor

On line 10, you have an else if that isn't followed by a {…} of any kind. You need to combine your conditions into a single statement, you can't just put two "else if" statements back to back.

Same goes for the first set of if statements. Try combining your conditions like this:

 

//Meters less than or equal to 1.0 inches and installed less than or equal to 15 years ago
if (($feature.metersize_inches <= '1.0') && (DateDiff(Now(), Date($feature.installdt), 'year') <= 15)) {
  return "Small Meters installed up to 15 years ago"
}

//Meters greater than or equal to 1.5 inches and installed less than or equal to 10 years ago
else if (($feature.metersize_inches >= '1.5') && (DateDiff(Now(), Date($feature.installdt), 'year') <= 10)) {
  return "Large Meters installed up to 10 years ago"
}

//Time since meter installation is none of these
else {
  return "None of these"
}

Edit: conditions should be AND (&&) not IF.

 

- Josh Carlson
Kendall County GIS
0 Kudos
JayHodny
Occasional Contributor III

Josh,

Excellent, that worked.  I figured my back-to-back approach was not correct, but I didn't know the correct way to combine conditions.  Now I do!  Thanks.

0 Kudos
KenBuja
MVP Esteemed Contributor

There were a couple of issues. First, you were using a string ('1.0') instead of a number to check for metersize_inches. Also, you were missing some curly braces in the if statements.

If I understand your logic, then this should work using the When function.

When (//Meters less than or equal to 1.0 inches and installed less than or equal to 15 years ago
      $feature.metersize_inches <= 1.0 && DateDiff(Now(), Date($feature.installdt), 'year') <= 15, "Small Meters installed up to 15 years ago",
      //Meters greater than or equal to 1.5 inches and installed less than or equal to 10 years ago
      $feature.metersize_inches >= 1.5 && DateDiff(Now(), Date($feature.installdt), 'year') <= 10, "Large Meters installed up to 10 years ago",
      "None of these");

 

0 Kudos
JayHodny
Occasional Contributor III

Ken, thanks!  I tried your code and it worked as well, and gave me meters counts against the criteria that seem to be more of what I was expecting.  I need to investigate further.

Ken and Josh, thank you both!!

0 Kudos