11

I am having some issues trying to show multiple fields for a single label in QGIS. In QGIS2.6, attempting to display labels for a feature consisting of multiple fields results in an empty label if one of the fields is null. So for example, in the label expression dialog:

concat("Temp Site",'\n',"Notes",'\n',"Function")

will function normally unless one of the fields is null, then it results in no label being shown. Using the '||' operator instead in the expression dialog also results in the same behaviour:

"Temp Site" || '\n'  ||  "Notes" || '\n'  ||  "Function"

Is there a way to display the labels even if one of the fields is null?

16

Use the "Coalesce" function. Coalesce takes the first non-null value from its arguments. So this expression should work:

coalesce("Temp Site",'') || '\n'  ||  coalesce("Notes",'') || '\n'  ||  coalesce("Function",'')
  • You can also wrap the new line within the coalesce function, if it makes sense to avoid the blank lines in the middle of the label I used an expression like coalesce("Temp Site", ' ') || coalesce(('\n' || "Notes"), ' ') || coalesce(('\n' || "Function"), ' ' ) – Brian Fisher Jan 22 '18 at 10:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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