4

I'm working with a column in an attribute table that has number values and NULL values. I want to create a new column in which NULL values are changed to "Directory" and any number values to "Submitted."

I used the formula from the answer from How to do a simple find and replace in QGIS field calculator? and successfully converted NULL to text.

enter image description here

How can I use a version of this formula to also convert all number values to the word "Submitted"?

3 Answers3

4

Add a "New_Field" of type Text. Select the values that are not NULL using "Select features using an expression" from the attribute table, and enter the following formula:

"Field_Name" is not null 

Where: "Field_Name" is the field that contains numbers (is not NULL). Then update the "New_Field" and write 'Submitted' in the expression, and use Update Selected, as shown below:

enter image description here

Then use Invert Selection enter image description here and write 'Directory' and click Update Selected.

Taras
  • 32,823
  • 4
  • 66
  • 137
ahmadhanb
  • 40,826
  • 5
  • 51
  • 105
1

If you want to verify if content is number, then try the below regexp:

CASE WHEN regexp_match(( "Field_Name" ) , '[0-9]') THEN 'submitted'  END
Shiko
  • 2,883
  • 13
  • 22
0

Use this expression to return 'Directory' for values of NULL and 'Submitted' for values containing a digit in the attribute named fieldname:

case 
when fieldname is NULL then 'Directory'
when fieldname ~ '[0-9]' then 'Submitted'
end

Like this, if field is not NULL and does not contain any digit, the output will be empty. You might define an else condition to set an output for such cases.

Babel
  • 71,072
  • 14
  • 78
  • 208