I am trying to get a certain expression in QGIS right, but because I am quite new to QGIS expressions, I cannot quite get it right.

Basically I want another field, to have specific kind of text based on the value of the pre-existing field. In this case, when the height of a tree ("Height" field) has the following values, the following text will be displayed:

  • <6 meters: >6 meters 3rd category
  • between 6-12 meters: 2nd category
  • >12 meters: 1st category

How exactly do I do this and what I am doing wrong here?

enter image description here

As for a side note, should I better do this using AutoFields plugin, so I am sure it happens automatically?

  • Regarding your last question, definitely! Use AutoFields to get the 'category' field up-to-date (e.g., when you insert or modify heights). Just use the expression given by @armoraer in the AutoFields dialog. Mar 20, 2017 at 16:07

1 Answer 1


You can use a CASE expression:

  WHEN "Hoogte" <= 6 THEN '6 meter, 3rde categorie'
  WHEN "Hoogte" >= 6 AND "Hoogte" <= 12 THEN '6-12 meter, 2de categorie'
  ELSE '12 meter, 1ste categorie'

I'm not sure what you mean by "autofields" though?

  • Beat me to it, good answer. To note, the "Hoogte" field must be numeric for this to work. The autofields, might refer to virtual fields, which can generate a field automatically based on this query. But probably best left for another question. Mar 20, 2017 at 15:55
  • AutoFields is a QGIS plugin that updates field values based on expressions. It writes the updated values directly in the source data. Mar 20, 2017 at 16:03

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.