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?

7
  • do you have a text field or a numeric field ?
    – radouxju
    Nov 27, 2018 at 8:44
  • I am not sure. How can I find out?
    – Papayapap
    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.
    – radouxju
    Nov 27, 2018 at 9:05
  • okay, it is string, yes.
    – Papayapap
    Nov 27, 2018 at 9:06
  • have you tried with 'no' in the field calculator ?
    – radouxju
    Nov 27, 2018 at 9:10

1 Answer 1

6

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.

13
  • 2
    Alternative: if( "field" IS NULL, 'no', "field"). Yours is of course more descriptive. :) 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?
    – Papayapap
    Nov 27, 2018 at 8:50
  • 1
    I usually use CASE WHEN because I find it easier to nest.
    – Erik
    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.
    – Erik
    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?
    – Papayapap
    Nov 27, 2018 at 9:01

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.