Select to view content in your preferred language

Utilising date in Arcade expression

80
4
Jump to solution
12 hours ago
Labels (1)
MattHouston353
New Contributor

I am creating a map of survey held by my employer. I am trying to use a simple 'traffic-light' symbology pattern to quickly see the survey age. So survey that is ten years or older will be red, 8-10 years amber and less than 8 will be green. The data contains a field called YEAR, contain the year as a number.

I'm attempting to symbolise using an expression but I'm a little overwhelmed by all the date options that appear. So far for my red symbol I have tried the following:

$feature YEAR > (DateOnly() + 10);
 
But YEAR is highlighted as an unexpected identifier. Any help appreciated.
0 Kudos
1 Solution

Accepted Solutions
JenniferAcunto
Esri Regular Contributor

You need an expression that determines all three of your symbols at once. 

 

When(Year(Today())-$feature.year >= 10, '10+', Year(Today())-$feature.year >= 8, '8-10', '<8')

 

 

This expression subtracts the feature year from the current year, and if the difference is greater than or equal to 10 then it goes into the 10+ bucket. If it is not, it keeps checking and looks to see if the difference is greater than or equal to 8. If it is, it goes in the 8-10 bucket. If not, it goes into the default bucket of <8. 

Note that I am using $feature.year, but that might be slightly different for you based on your Year field name. The easiest way to determine what that value should be, is to use the variable picker to add it to your expression for you. 

 
 

JenniferAcunto_3-1739194119174.png

 

In the style panel, you can then assign your desired symbology to those buckets. 

JenniferAcunto_0-1739193746414.png

 

 

- Jen

View solution in original post

0 Kudos
4 Replies
LeeButler
Esri Contributor

Does this work for you:

if ($feature.year > (Year(Now()) + 10));

This uses the Year() function with the Now() function to get the current year:

Date functions | ArcGIS Arcade | Esri Developer

0 Kudos
MattHouston353
New Contributor

Hmmm no it still seems to capture all the features; I also had to remove the 'if'. 

0 Kudos
JenniferAcunto
Esri Regular Contributor

You need an expression that determines all three of your symbols at once. 

 

When(Year(Today())-$feature.year >= 10, '10+', Year(Today())-$feature.year >= 8, '8-10', '<8')

 

 

This expression subtracts the feature year from the current year, and if the difference is greater than or equal to 10 then it goes into the 10+ bucket. If it is not, it keeps checking and looks to see if the difference is greater than or equal to 8. If it is, it goes in the 8-10 bucket. If not, it goes into the default bucket of <8. 

Note that I am using $feature.year, but that might be slightly different for you based on your Year field name. The easiest way to determine what that value should be, is to use the variable picker to add it to your expression for you. 

 
 

JenniferAcunto_3-1739194119174.png

 

In the style panel, you can then assign your desired symbology to those buckets. 

JenniferAcunto_0-1739193746414.png

 

 

- Jen
0 Kudos
MattHouston353
New Contributor

This worked perfectly, thank you!

0 Kudos