2

This question already has an answer here:

I need to converte NULL values to 0 values with the overall goal of sum up two columns in attribute table in QGIS. Since one of these colums has NULL values, the new column with the sum also appears with NULL value (instead of preserving numeric value of other column).

I have tried Selecting column by all NULL value and putting 0 in Expression Field but that does not work.

Any ideas on how to do it?

marked as duplicate by Chris W, PolyGeo May 14 '15 at 2:16

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • It is a little unclear what you are asking. Can you attach a screen shot with an example output or anything showing clearly what you are trying to accomplish? Please edit your original question to add more information. Also form a better question than just any ideas? – Brad Nesom May 13 '15 at 16:51
  • 1
    Have you tried looking at the value as if value is None: for your comparison? Like do that first then sub in 0 for the value. – Branco May 13 '15 at 17:11
  • @Andrea The coalesce function of field calculator works nicely for your requeriment. – xunilk May 13 '15 at 21:55
  • Duplicate? The objetive was to sum two columns in attribute table ignoring NULL values (so, the question was bad formulated). My solution is shorter than the another answer and it doesn't need to change NULL values in zeros previously to get the sum. – xunilk May 15 '15 at 22:06
2

If your problem is equivalent to this (where test3 is the sum of test + test2):

enter image description here

you can solve it with the coalesce function (Conditionals) of field calculator of QGIS.

The sintaxis (for the sum) is in the next image (NULL values are changed by zeros):

enter image description here

Afterward OK, the values in test3 (update existing field) are calculated, as espected, in the following image:

enter image description here

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