0

I have a trench containing five types of ducts. I have created fields the trenches: Type1, Type2, Type3, ...

The values in each field are the numbers of each type of duct that the trench contains.

eg. lets say that one trench contains 2 ducts of type one and one duct of type 2, then I would like to label it something like this: 2xType1,Type2

The other types are NULL. How can I write a compact expression to handle this?

1
  • 3
    What have you tried? You should be able to use the coalesce function in a label expression to hande nulls
    – Bera
    Commented Feb 28, 2019 at 10:27

1 Answer 1

3

Maybe use something like the following:

replace(
if("Type 1" > 0 and "Type 2" > 0, "Type 1" || 'x Type1, ' || "Type 2" || 'x Type2', 
if("Type 1" = 0 or "Type 1" IS NULL, "Type 2" || 'x Type2', 
if("Type 2" = 0 or "Type 2" IS NULL, "Type 1" || 'x Type1', ''))), '1x', '')

Example

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.