# Using nested If statement in Python parser of ArcGIS Field Calculator?

I'm trying to use field calculator to assign values to a new field I created. I wan't to assign the value from the first field unless that field is empty, if it is empty use field 2, if that is empty use field 3. Here is what I have thus far. I feel it is way off but not sure where to go from here.

New_Size: My new field

wmDeviceEq: First field to check for new field name

wmDevice_4: Second ""

wmDevice_5: Third ""

In the codeblock, you can only use parameters, not field names. You'll need to create parameters for each of your field names, like so:

def Reclass(f1, f2, f3): New_size = f1 # this doesn't actually do anything if f1 ==": return f2 elif f2 =="return f3 else: # is this cutoff? return f1 # New_size maybe?

and then

Reclass(!wmDeviceEq!, !wmDevice_4!, !wmDevice_5!)

What iff3(wmDevice_5) is empty? Not sure if your picture is showing a cuttoffelsestatement.

Are the values in the fields actually empty strings? Shapefiles store a single space" "and feature classes in a geodatabase typically use, which in Python would beNone.

If the fields are actually empty strings and only one field will ever have data, you don't need the code-block at all.

"".join((!wmDeviceEq!, !wmDevice_4!, !wmDevice_5!))

As an aside, a nestedifstatement would be something like this:

if result > 10: print("Greater than 10") if result < 100: print("and less than 100") else: print("It's big… ") else: print("Too small!")

@Paul

I edited the code and came up with this

def Reclass( ph1, ph2, ph3 ): New_Size = ph1 if ph1 ==": return ph2 elif ph2 ==": return ph3 elif ph3 ==": print ("NULL")

and then

Reclass(!wmDeviceEq!, !wmDevice_4!, !wmDevice_5!)

When it runs my new field pulls values from only ph2… Also not sure about that final elif. it's meant to fill a space that has no value to pull, with a "Null".

I tried the "".join() function but it places spaces every time it moves to the next field, like so.

Won't work unless there is a way to remove those spaces before the values in the New_Size field.