Select to view content in your preferred language

Symbology based on current year?

270
2
07-17-2025 11:30 AM
ATeitelb
New Contributor

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.

 

 

Tags (3)
0 Kudos
2 Replies
DanPatterson
MVP Esteemed Contributor

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 


... sort of retired...
0 Kudos
KenBuja
MVP Esteemed Contributor

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.