If-then statement in field calculator

5920
5
Jump to solution
07-20-2015 02:13 PM
by Anonymous User
Not applicable

I am new to scripting and am trying to figure out how to write an If-then statement to populate a field in field calculator.  I want to basically say if a certain field has a NULL value in it, then the result is "No" in that field.  If the certain field has a value in it, then I want the result to be "Yes".

0 Kudos
1 Solution

Accepted Solutions
by Anonymous User
Not applicable

Thank you everyone for your help!  I was able to accomplish what I wanted by doing a selection query and field calculating on the results.

View solution in original post

0 Kudos
5 Replies
JoeBorgione
MVP Emeritus

Not sure it's possible; my work around has always been to create a selection and calc your value.

select:  'TheField' is null

That should just about do it....
IanMurray
Frequent Contributor

It would be something like this.

Expression:

Reclass(!FieldwithNullValuesHere!)

Expression Type:

Python_9.3

Code Block:

def Reclass(field):

  if field == "None":

    return "No"

  else:

    return "Yes"

0 Kudos
DarrenWiens2
MVP Honored Contributor

This is assuming your field is actually <Null>, not blank, or something else:

Codeblock:

def blah(field):
  if field:
    return "Yes"
  else:
    return "No"

expression:

blah(!yourfield!)
FreddieGibson
Occasional Contributor III

See the following Esri Documentation and look for the section titled "Using Code Blocks"

Calculate Field Examples

http://desktop.arcgis.com/en/desktop/latest/manage-data/tables/calculate-field-examples.htm

0 Kudos
by Anonymous User
Not applicable

Thank you everyone for your help!  I was able to accomplish what I wanted by doing a selection query and field calculating on the results.

0 Kudos