1

I am new to QGIS. This question about how to use the field calculator, because the procedure to replace all fields is explained very nicely in Replacing all null values from attribute table with zeros using QGIS?

I have the null features selected, but now I am struggling to find a means to change all of them to "no" instead of the "0".

Can someone help?

PolyGeo
65.5k29 gold badges115 silver badges350 bronze badges
asked Nov 27, 2018 at 8:39
7
  • do you have a text field or a numeric field ? Commented Nov 27, 2018 at 8:44
  • I am not sure. How can I find out? Commented Nov 27, 2018 at 8:54
  • QGIS 3 : right click on layer > properties > identify icon (i in blue circle), then scroll to fields and you will see the type of field. Commented Nov 27, 2018 at 9:05
  • okay, it is string, yes. Commented Nov 27, 2018 at 9:06
  • have you tried with 'no' in the field calculator ? Commented Nov 27, 2018 at 9:10

1 Answer 1

8

Update your column using the following "code" in the field calculator

CASE WHEN "field" IS NULL THEN 'no' ELSE "field" END

This doesn't even need you to select all NULL-values beforehand - and requires your column to not to be of any numerical data type.

answered Nov 27, 2018 at 8:42
13
  • 3
    Alternative: if( "field" IS NULL, 'no', "field"). Yours is of course more descriptive. :) Commented Nov 27, 2018 at 8:46
  • Thanks Erik and Stefan, and for the "field" I should put the name of my variable without the quotations, yes? Commented Nov 27, 2018 at 8:50
  • 1
    I usually use CASE WHEN because I find it easier to nest. Commented Nov 27, 2018 at 8:50
  • "field" is you columns name - and you have to use the quotation marks. Column names are always refered to by double quotation marks, values (especially strings) by single quotation marks. Commented Nov 27, 2018 at 8:52
  • That's good to know, thanks. For me the code doesn't work. I put it in the field calculator, replaced the column name, and checked the "update existing field option" but when I click on "ok" nothing happens. Do you have an idea what is happening? Commented Nov 27, 2018 at 9:01

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.