I have a polygon layer which contain information on property name, number of trees within the polygon, average height, and min- and max height values.

My problem is, I want to label each polygon with property name, number of trees, etc. I got that part to work, the labels looks the way I want them. But, I have a number of properties which doesn't contain any trees. When making labels, the properties without tree doesn't get labelled at all?

I would like labels on the properties without trees to show just the names of the properties. Is this possible in QGIS 2.2?

2 Answers 2


There's two ways you could do this. One is to wrap your field that contains some nulls by the 'coalesce' function:

Coalesce("tree_field_name", '0 trees')

This would use the value in tree_field_name if it's non null, otherwise it will use the string '0 trees' (pay attention to the use of " and ').

The alternative is to use a "case when" function:

Case when "tree_field_name" is null then '0 trees' else "tree_field_name" end

This will have the same result.

  • Thank you for your answer! I think I got it to work. One more question, can I somehow leave the "when "tree_field_name" is null then..." blank? This way works too, but my plan was to get the properties without trees just labelled with the names of the properties.
    – SoS
    Aug 19, 2014 at 9:18
  • When "tree_field_name" is null then '' should work. That's two ' characters with nothing between them.
    – ndawson
    Aug 19, 2014 at 10:01

I came up with a solution to my problem.

I saved all the properties without trees in a new shapefile. Then I labelled the new layer with property names. So now i have two layers, one with the polygons of all the properties and labels on the ones with trees and one layer with only the labels of the properties without trees. When I show them together I get the result I wanted.

If possible, I still really want to learn how do this without creating a new layer.

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.