Hi all,
I have a point layer for which I would like the symbology to reflect two attributes of a feature. The first would be a binary yes/no, and the second would be based on the current year. The way I would like it to work is:
1. If yes, then color = black.
2. If no, then reference "Year".
3. If "Year" = current year or prior to current year, then color = green
4. If "Year" = current year + 1, then color = yellow
5. If "Year" = current year + 2 or longer, then color = red
The issues I am running into are with the "Year" field. The first issue is creating a Date field which only requires YYYY. I do not need a day or month for this data. A text or integer field solves this, but then the number is not seen as a year to be compared to the current year.
I would prefer not to, but if I use 1/1/YYYY as a placeholder date, I am not seeing a way to compare the date field to "current date" to inform the symbology.
Thank you all in advance for any assistance.
you could use the field calculator to just get the year
import datetime
n = datetime.datetime.now() # substitute 'n' for with !YourFieldName!
# datetime.datetime(2025, 7, 17, 14, 48, 24, 69857)
# as a string
n.strftime("%Y")
'2025'
# as an integer
int(n.strftime("%Y"))
2025
. The datetime functions are available in the field calculator, python parser
This Arcade script is one way to do that, assuming your Yes/No field is called Binary and the date field called Date. This will return values that you can symbolize with the correct colors
var theYear = Year($feature.Date);
var currentYear = Year(Now());
if ($feature.Binary == "Yes") return "black";
When(
theYear <= currentYear, "green",
theYear == currentYear + 1, "yellow",
"red"
);
Line 1 gets the year of the point's date.
Line 2 gets the current year.
Line 4 returns "black" if the Binary field is Yes
Line 5 uses the When function (and uses an implicit return)
Line 6 returns "green" if the point's year is equal to or prior to the current year.
Line 7 returns "yellow" if the point's year is the next year.
Line 8 returns "red" if the point's year is after the next year.