I try to make labels with several lines in the main map in QGIS. I tried the formula, just after but it shows me the first condition without doing the others.

IF ("sensitivity" = 'A3', 'A3:' || ceil ($ length), '') || IF ("sensitivity" = 'A4', 'A4:' || ceil ($ length), '') || IF ("sensitivity" = 'A2,' A2: '|| ceil ($ length),' ')

if I had to add a field the function would have worked, on the other hand when I put it in a label (see photo in attachments) it does not work (see photo) he checks the first condition is stopped on it he does not look at the others (see photo) enter image description here

enter image description hereng

  • Hi there welcome to GIS SE! Could you elaborate on the expected behaviour and what isn't working? There is also this question about wrapping labels onto multiple lines gis.stackexchange.com/questions/30084/… – GISKid Feb 3 '20 at 23:07
  • 3
    This expression can only show one label. Your field "sensitivity" can never be 'A3' and 'A4' at the same time. So all the other concatenated if expressions jump to their else part, which is ''(empty). I think it could help us to help you if you provide a sample data and an example of the expected output because i think "multiple lines" is not what you are really after. – MrXsquared Feb 3 '20 at 23:43

If you fix the last misplaced quote, the expression will display either A2 or A3 or A4

IF ("sensitivity" = 'A3', 'A3:' || ceil ($length), '') || IF ("sensitivity" = 'A4', 'A4:' || ceil ($length), '') || IF ("sensitivity" = 'A2','A2: ' || ceil ($length),' ')

You could also rewrite it. Instead of displaying nothing if the condition is not met, you nest the next condition

if("sensitivity" ='A2','A2: ' || ceil($length),if("sensitivity" ='A3','A3: ' || ceil($length),if("sensitivity" ='A4','A4: ' || ceil($length),'')))

But it would be even simpler to check for all conditions at once

if("sensitivity" IN ('A2','A3','A4'),"sensitivity" ||': ' || ceil($length),'')

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