1

I have several columns with certain values, here's an example:

  | Apple | Banana| Orange | Pear       | Expected result
  | 1     | 1     | 1      | 1          | red
  | 1     | 2     | 2      | 1          | green
  | 2     | 1     | 1      | 1          | red
  | 2     | 2     | 2      | 1          | green

I would like to add ALL columns ONLY when the values are 2. I'm using this as a style filter so there will be colour ranges (i.e. Apple + Banana + Orange + Pearis less than 4 then red; equal or greater than 4 then green).

Can this be done?

The following is, I think, close to what I want but it gives red for all results instead of the expected results as shown above:

case when "Apple" IN ('2') + "Banana" IN ('2') + "Orange" IN ('2') + "Pear" IN ('2')
>=4 then 'green'
else 'red'
end
  • Unfortunately, the rule description is not yet completely clear for me. Please clarify: Would it be correct to say that you want to count how often the value 2 appears in a line? And if it appears at least twice, the color should be green? – underdark Sep 10 '14 at 14:15
  • @underdark, yes that is exactly what I am looking for. – Joseph Sep 10 '14 at 14:24
2

This should work:

CASE
WHEN ("Apple" = 2) + ("Banana" = 2) + ("Orange" = 2) + ("Pear" = 2) >= 2
THEN 'green'
ELSE 'red'    
END

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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