2

I want to make an label expression to label with "pHole_ID" if the "Status" is 'Planned' and label with "ActualHole_ID" if the "Status" is 'Completed'.

I have tried:

case 
  when "Status" like 'Planned' then "pHole_ID" 
  else "Status" like 'Completed' then "ActualHole_ID" 
end

but to no avail.

2 Answers 2

4

If you want to use a single expression rather than (the perfectly fine) rule based solution from @Maximilien jaffrès you should use two WHEN for your expression so :

CASE
  WHEN "Status" like 'Planned' THEN "pHole_ID"
  WHEN "Status" like 'Completed' THEN "ActualHole_ID"
  ELSE 'not in rule'  (use the ELSE only if you want a label when the rules return noting, if not remove the whole line)
END

Also you use the like operator but dont use any wildcard so you should use something like this WHEN "Status" like '%Planned%' if you want all entry of "Status" that contain the string 'Planned' (or simply use WHEN "Status" = 'Planned' to get entry where "Status" contains exactly the string 'Planned')

4

You should use labelling with rules and lay down your rules in unique row

for exemple i made this rule :

if "validity" = True i use column "z_crest1"

if "validity" = False i use column "z_crest2"

enter image description here

In your case it should be something along the line of

if "Status"= 'Planned' use "pHole_ID"

if "Status" = 'Completed' use "ActualHole_ID"

Note that you can also use else in theses expressions and declare as many rules as you need.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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