Select to view content in your preferred language

Arcade Expression to Symbolize Past Due Assignments

763
3
05-25-2022 09:38 AM
JasonCyphers
Frequent Contributor

I have a point feature that identifies locations to be inspected that month.  The feature has a "Due Date" attribute, which is typically the last day of the month.

I'd like to symbolize, in Field Maps, any point that has not been completed, based on the due date; so, I attempted to write the below arcade expression which looks at today's date, compares it to the month of the features due date attribute, and if the due date is the same month as Today(), then symbolize it as "Due This Month".  If the due date is last month, symbolize it as "Past Due":

var DateDifference = DateDiff(Today(), Month($feature["due_date"]), "month")
if (DateDifference < 1){
return 'Due This Month'
}
else {
return 'Past Due'
}

The expression, however, doesn't appear to work... everything regardless of the due date (even if the due date is the end of this month) is being symbolized as "Past Due".

Any guidance would be appreciated.  I'm a novice w/ arcade expressions.

 

3 Replies
JustinReynolds
Frequent Contributor

I'm assuming that this is a form Calculation and that this calculation is on the field that controls symbology (unique renderer).

@jcarlson below is on the right track with DateDiff. DateDiff aside, be careful with the Month function it is zero indexed. So January is 0 and December is 11.  When using it you might need to do  Month($feature["due_date"]) +1.

- Justin Reynolds, PE
0 Kudos
jcarlson
MVP Esteemed Contributor

I think the key is "Month($feature["due_date"])".

Month is going to return a number corresponding to the month, whereas DateDiff is looking for two datetime values.

Tip: Make use of the Console function to print out intermediate values to double-check things.

jcarlson_0-1653499299125.png

If I was using Month on the other date, I would more easily catch this:

jcarlson_1-1653499444735.png

 

So, just try running your expression against the two dates and leave the Month function out.

Also, when it's a simple either/or, Iif can be more concise to write than a full if... else block.

- Josh Carlson
Kendall County GIS
KenBuja
MVP Esteemed Contributor

The reason it's always returning 'Past Due' is the Month function will return a number between 0 and 11. The DateDiff function sees the second parameter as just a number, not a date, so it return NaN (not a number). You should use this:

 

var DateDifference = DateDiff(Today(), $feature.["due_date"], 'month')