Nested if statement in QGIS label expression
I think you need a CASE
statement, which will allow you to have different conditions.
Something like:
CASE
WHEN Veg_codon <> '' AND Veg_ondeg <> '' THEN Veg_dom + Veg_codom + '('+Veg_onderg+')'
WHEN Veg_codon <> '' AND Veg_ondeg = '' THEN Veg_dom + Veg_codom + '(some default value)'
WHEN Veg_codon = '' AND Veg_ondeg <> '' THEN Veg_dom + 'default value' + '('+Veg_onderg+')'
...
END
Solution: Both the IF statements and the CASE statement work. I misused the = '' sign where I should have used IS NULL, to specify a cell is empty. So:
if( Veg_codom <> ' ' AND Veg_onderg <> ' ',
Veg_dom + '+' + Veg_codom + '+' + concat('(', Veg_onderg, ')'),
if( Veg_codom IS NULL AND Veg_onderg <> ' ',
Veg_dom + '+' +concat('(', Veg_onderg, ')'),
if( Veg_codom <> ' ' AND Veg_onderg IS NULL,
Veg_dom + '+' + Veg_codom,
Veg_dom)))