Hi there,
I am trying to symbolize the expiry dates of applications and would like to group them in 4 year time groups.
I am currently using the Arcade expression:
return Month($feature.Expires) + "/" + Day($feature.Expires) + "/" + Year($feature.Expires)
And would like to know how to group it so one class is 20/01/2030 - 20/01/2034 and the next class is 21/01/2034 - 21/01/2038?
I have tried simply symbolizing it based on the attribute but it does not appear in the symbology drop down pane.
Any tips? Thanks!
Solved! Go to Solution.
Go into the symbology pane, choose Unique Values, click on Set an expression, paste the code below.
var exp_date = $feature.Expires
var start_date = Date(2030, 0, 21) // start of the first class (month is 0-based)
var year_delta = 4 // class width
for(var i = 0; i < 50; i++) { // try 50 times
// get end_date
var end_date = DateAdd(start_date, year_delta, "years")
end_date = DateAdd(end_date, -1, "days")
// if in class, return
if(exp_date >= start_date && exp_date <= end_date) {
return Text(start_date, "DD/MM/Y") + " - " + Text(end_date, "DD/MM/Y")
}
// else increment the start date
start_date = DateAdd(start_date, year_delta, "years")
}
// if no class found after 50 times, return default value
return "unclassed"
Note that I followed the date format of your text (DD/MM/Y), not the one in your expression (MM/DD/Y). You can change that in line 11.
Go into the symbology pane, choose Unique Values, click on Set an expression, paste the code below.
var exp_date = $feature.Expires
var start_date = Date(2030, 0, 21) // start of the first class (month is 0-based)
var year_delta = 4 // class width
for(var i = 0; i < 50; i++) { // try 50 times
// get end_date
var end_date = DateAdd(start_date, year_delta, "years")
end_date = DateAdd(end_date, -1, "days")
// if in class, return
if(exp_date >= start_date && exp_date <= end_date) {
return Text(start_date, "DD/MM/Y") + " - " + Text(end_date, "DD/MM/Y")
}
// else increment the start date
start_date = DateAdd(start_date, year_delta, "years")
}
// if no class found after 50 times, return default value
return "unclassed"
Note that I followed the date format of your text (DD/MM/Y), not the one in your expression (MM/DD/Y). You can change that in line 11.
Hi Johannes, thank you for that that did the trick!