How to not display NULL Values in a string label

5892
5
03-20-2017 09:16 AM
KevinWyckoff2
New Contributor

I have a feature class that I want to label based on three fields. It would be great if the first two fields always displayed, and the third only displayed when it isn't null. I have added all the field to a label no problem like this:

Is it possible to eliminate the word NULL in three of the five examples above?

Tags (1)
5 Replies
JayantaPoddar
MVP Esteemed Contributor

You could use Using label classes to label features from the same layer differently—Help | ArcGIS for Desktop .

Create two classes and define SQL Query to identify the subset of the features you want to label in each class.

1. [Field3] IS NULL

2. [Field3] IS NOT NULL

Label Expression for Class 1

[Field1] + " " + [Field2]

Label Expression for Class 2

[Field1] + " " + [Field2] + " " + [Field3]



Think Location
JoshuaBixby
MVP Esteemed Contributor

In addition to using label classes, you can define a FindLabel function (make sure to check 'Advanced'):

Expression:

def FindLabel( [Field1], [Field2], [Field3] ):
    return " ".join(str(field) for field in ( [Field1], [Field2], [Field3] ) if field)

Parser:

Python

NinaRihn
Occasional Contributor III

you could add this vb expression:

Function FindLabel ([field 1], [field 2], [field 3])
If [field 3] <> " " then
    FindLabel = [field 1] & " " & [field 2] & " " & [field 3]
else
    FindLabel = [field 1] & " " & [field 2]
end if
End Function

this works for me even with Null values

AbdullahAnter
Regular Contributor II

If you have Null values in your field , it is automatically doesn't appear in label.

Just use simple expression: parser VBScript >

[Field1] & [Field2] &[Field3] 

0 Kudos
NinaRihn
Occasional Contributor III

that is true, however the vb expression comes in handy if you would like to add characters or spaces between each value, like this:

Function FindLabel ([field 1], [field 2], [field 3])
If [field 3] <> " " then
    FindLabel = [field 1] & "-" & [field 2] & "-" & [field 3]
else
    FindLabel = [field 1] & "-" & [field 2]
end if
End Function

then the last dash doesn't show up if the last value is null