Select to view content in your preferred language

conditional label

650
6
Jump to solution
02-02-2024 07:38 AM
RobertCottreau
New Contributor II

I'm trying to create an expression in ArcGIS Online to label a polygon as "Closed" if today's date falls between the date in the ClosedDate field and the ReopenDate field but not to label anything if it is not between those dates or if either of those fields is blank/empty.

I can't have a field with "Closed" as there are popups and I don't want this text to confuse the user.

Thanks to all.

Tags (3)
0 Kudos
1 Solution

Accepted Solutions
KenBuja
MVP Esteemed Contributor

You can use this syntax

if ($feature.ClosedDate <= Today() && Today() <= $feature.ReopenDate) return "Closed";

View solution in original post

0 Kudos
6 Replies
KenBuja
MVP Esteemed Contributor

You can use this syntax

if ($feature.ClosedDate <= Today() && Today() <= $feature.ReopenDate) return "Closed";
0 Kudos
RobertCottreau
New Contributor II

This work perfectly.  Thanks, Ken.

And it automatically excludes any instances where the ClosedDate and/or ReopenDate fields are blank?

0 Kudos
KenBuja
MVP Esteemed Contributor

Would both of them be blank or would you have cases where only one is blank?

0 Kudos
KenBuja
MVP Esteemed Contributor

A better question is what would you want to see if one if blank and the other isn't.

0 Kudos
RobertCottreau
New Contributor II

they could both be blank because some fields aren't closed at any time in which case there is no label

0 Kudos
KenBuja
MVP Esteemed Contributor

The only case where it wouldn't return null with blank fields is if the ClosedDate was blank and the ReopenDate was after today. That would return "Closed". That's why I was asking what you would want to show if one field was blank but the other had a Date.

You can test the variants in the Arcade Playground with this code.

var ClosedDate = null;
//var ClosedDate = Date(2024,1,1);
var ReopenDate = Date(2024,1,14);
//var ReopenDate = null;
if (ClosedDate <= Today() && Today() <= ReopenDate) return "Closed";

 

0 Kudos