Select to view content in your preferred language

Field-dependent labeling for one set of features

167
2
10-08-2024 04:37 PM
ElliottD
Emerging Contributor

In Pro 3.3, I have a set of cities whose names I want to label based on two fields, NAME and NAMEALT. If the city has a NAMEALT, I want to use that name. If it does not, I want to default to NAME. I thought that by using defaultValue in Arcade (see screenshot), it would return the NAME value if no NAMEALT value was detected. What am I doing wrong?

ElliottD_0-1728430421189.png

 

Tags (3)
0 Kudos
2 Replies
BarryNorthey
Frequent Contributor

I did a few tests and the syntax appears to be correct. The value field might have invisible blank spaces that could cause the problem. Python lstrip() can remove leading blank spaces.

 

0 Kudos
VinceE
by
Frequent Contributor

I think @BarryNorthey is right. See below, where my third point, OBJECTID 7, does not show because the whole field is just spaces (so it is labeling, but it's unseen because it's spaces!).

VinceE_0-1728487029561.png

An alternative to the suggestion above using Python would be to improve your label expression to TRIM white space.

// Use Trim() to reduce a field full of spaces down to "".
DefaultValue(Trim($feature.Label_Main), $feature.Label_Backup)

And now here is what we have, because the "Label_Main" values is reduced from "       " down to "", and therefore is considered Empty, and then defaults to the Label_Backup.

VinceE_1-1728487207693.png

 

 

0 Kudos