Symbolise points based on time periods?

494
2
Jump to solution
01-12-2022 05:03 PM
Hayley
by
Occasional Contributor II

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!

HL
0 Kudos
1 Solution

Accepted Solutions
JohannesLindner
MVP Frequent Contributor

Go into the symbology pane, choose Unique Values, click on Set an expression, paste  the code below.

JohannesLindner_0-1642054955747.png

 

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.


Have a great day!
Johannes

View solution in original post

2 Replies
JohannesLindner
MVP Frequent Contributor

Go into the symbology pane, choose Unique Values, click on Set an expression, paste  the code below.

JohannesLindner_0-1642054955747.png

 

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.


Have a great day!
Johannes
Hayley
by
Occasional Contributor II

Hi Johannes, thank you for that that did the trick!

HL
0 Kudos