1

Using QGIS 2.2, I would like to create a rule-based filter whereby you add 2 columns together and you get a certain colour as a result. However, some fields in Column_1 may be NULL and those exact same fields may have values in Column_2 and vice-versa.

Is there an expression to add the 2 columns whilst ignoring the NULL values or atleast treating them as zero?

The following is the logic I am trying to achieve:

1 + 2 = 3

1 + NULL = 1

NULL + 2 = 2

Additional info: The data from the columns are JOINED from other layers, I do not want to create any new columns as I am wanting the colours of layers to dynamically change when the user adds or removes the JOINED layers.

1 Answer 1

2

Found a link which contained solutions to adding 2 layers or more:

https://stackoverflow.com/questions/1769648/addition-with-null-values

Basic gist is when using 2 columns:

coalesce("Column_1"+"Column_2","Column_1","Column_2")

Using 3 columns or more, I used:

coalesce("Column_1",0.00) + coalesce("Column_2",0.00) + coalesce("Column_3",0.00) + .......

Your Answer

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

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