4

How do you write an expression for a style rule that will check if the value from column A exists in columns B, C, D & E?

I have a polygon layer that I would like to flag with a style depending on whether the values from column 'MH#' are found in any of the 'MH1-MH4' columns.

Example:

record 39: MH# 883031 is found in the MH2 column of record 38, I'll make it red.

record 42: MH# 883777 is found in the MH1 column of record 37, I'll make it red.

record 37: MH# 882516 is not found in any of the MH1-MH4 columns, I'll make it yellow.

example

4
CASE WHEN array_contains(array_distinct(array_agg("MH1")), "MH#")  
       OR array_contains(array_distinct(array_agg("MH2")), "MH#")
THEN color_rgb(255,0,0)
ELSE color_rgb(255,255,0)
END

enter image description here

  • 3
    This check only for the MH1 and MH2 column (but it's just a matter of adding two more OR line for the two other column if you want to check the four column) – J.R Sep 5 at 9:25
  • That's just what I was looking for, thank you for the very useful answer. – CEL-ma Sep 5 at 11:46

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.