I am trying to categorize data using arcade and dates. It worked on a previous project but not working on the new dataset. If the date is older than today - call it red. If within 1 year - call it yellow and if over 1 year from now call it green. I only seem to get one response of Red, but the data has values that should give me all three categories.
var year = DateDiff(Now(), $feature["Next_Audit_Date"],'years');
return When(year <= 1, 'Yellow', year > 1, 'Green', 'Red');
Solved! Go to Solution.
Are you sure you're getting a valid value from the DateDiff function? If it's an invalid number (NaN), then your When will return 'Red'. Otherwise, I can't see a way of getting 'Red' from the way your logic is set up. This code seems to be what you're trying to get. Note that you shouldn't use reserved words (like "year") for variable names.
var theYear = DateDiff($feature["Next_Audit_Date"], Now(), 'years');
console(theYear);
return When(theYear <= 0, 'Red',
theYear <= 1, 'Yellow',
theYear > 1, 'Green',
'Invalid');
Are you sure you're getting a valid value from the DateDiff function? If it's an invalid number (NaN), then your When will return 'Red'. Otherwise, I can't see a way of getting 'Red' from the way your logic is set up. This code seems to be what you're trying to get. Note that you shouldn't use reserved words (like "year") for variable names.
var theYear = DateDiff($feature["Next_Audit_Date"], Now(), 'years');
console(theYear);
return When(theYear <= 0, 'Red',
theYear <= 1, 'Yellow',
theYear > 1, 'Green',
'Invalid');
Ken - thanks for the advice on reserved words. I will pay more attention to that. Using your example in Pro provides the result I'm looking for. I was attempting to apply with the MapViewer in on-prem Portal. That still seems to fail, but I'll work around that.
Thank you.