2

My data:

n1    n2    n3    NEW_COLUMN
11    null  null
null  33    null
null  null  55

My desired result:

n1    n2    n3    NEW_COLUMN
11    null  null  11
null  33    null  33
null  null  55    55
Joseph
  • 75,746
  • 7
  • 171
  • 282
Frank gu
  • 91
  • 3
  • 1
    Have a read of http://gis.stackexchange.com/questions/39168/elseif-conditional-statement-in-qgis-field-calculator and use the IsNull operator. – Michael Stimson Jul 03 '15 at 00:47
  • 1
    Will there always be only a single non-null value for any given row? If not, how do you pick which one? – Chris W Jul 03 '15 at 21:21

1 Answers1

2

You could simply use the Coalesce function which returns the first non-NULL value from the given columns (fields). Insert this expression into the Field Calculator as a new field:

coalesce( "Field_1", "Field_2", "Field_3" )

Below is a simple example:

Simple example

Field calculator

Result


If a feature has columns with multiple values (eg. 1, NULL, 3), then you may need to include ElseIf statements to decide which values to take.

Hope this helps!

Joseph
  • 75,746
  • 7
  • 171
  • 282