2

I'm labelling features with an simple expression to show [Number] + [Code], however, I have some null values in "Number".

When I use this expression it only labels the features with both number and code, however, I need it to display both, columns even if there is no value.

i.e. if there's no number display only display the code, if there's a number and a code, display both.

Do I need an Advanced level license to do this?

2 Answers 2

3

It's easy to do with using label classes.

Define two classes with SQL query:

Number is null

and

Number is not null

Then label each of the classes with the fields needed.

1
  • Thank you, that worked a treat. It also didn't help that I had the "label features in this class" turned off when I'd tried something similar the first time.
    – Claire
    Feb 1, 2016 at 16:59
3

You can easily do this with an advanced label expression.

For example, I've got a label expression that will take 2 fields and label with whichever of the fields is present, or both. You could do something like the following: enter image description here

Important notes about the code provided:

  • Obviously you would have to change the code to use your own field names
  • In the Label Expression dialog, you have to switch the parser to Python, or write your own label expression in your chosen language.
  • You have to make sure the "Advanced" check box is selected/turned on.
  • The provided code will actually create stacked labels (Field_1 on one line and Field_2 on the next line). If you want it to all be on one line separated by a space, you can change the "\n" at the end of the 4th line to just be a space in quotes " "

Code provided below so you can copy past instead of re-typing from screen shot:

def FindLabel ( [FIELD_1], [FIELD_2] ):
  lbl = ""
  if [FIELD_1] <> None:
    lbl += str([FIELD_1]) + "\n"
  if [FIELD_2] <> None:
    lbl += str([FIELD_2])
  return lbl 

Let me know if I need to clarify anything in it for you.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.