4

Scenario:

I have four fields: A, B, C and D

Field A is text-based and contains values from '000' up to some number 'xxx' Field B contains a set of values (also text, but represented by numbers) Field C contains a set of values (also text, but represented by numbers) Field D is empty and waiting to be populated

I would like to construct an if-then statement in Field Calculator that does something like this:

If Field A = 000 then Field D = Field B, 
If Field A =/= 000 then Field D = Field C

I have spent the better part of my day trying to find the proper 'language' to ask Field Calculator, but I'm stuck. I have 0 programming experience also.

Could anybody show me how this should be set up either in Python?

I'm using ArcGIS 10.0.

PolyGeo
65.5k29 gold badges115 silver badges350 bronze badges
asked Nov 22, 2013 at 16:43

2 Answers 2

8

Using Python, the calculation would look like this:

For the Pre-Logic Script:

def Calc(a,b,c):
 if a == "000":
 return b
 else:
 return c

For the expression:

Calc( !A! , !B! , !C! )
answered Nov 22, 2013 at 17:07
3
  • Hi Thanks for the reply! I was not able to get this script to work....should it be used in Python or Python_9.3? Also when I go to insert the real names of my fields, they always have the exclaimation points before/after. Should they also appear that way in the Pre-logic script? Commented Nov 22, 2013 at 18:47
  • In the pre-logic, the variable names are simply placeholders and can be called whatever you like. Commented Nov 23, 2013 at 15:55
  • Wow - ok thanks nmpeterson for pointing that out. Totally worked! Many, many thanks! Commented Nov 25, 2013 at 16:20
1

Pythonic inline if is working in Field Calculator expression

res=(on_false, on_true)[condition]

arcpy.CalculateField_management("fc" , "field" ,"(!C!, !B!)[!A!=='000']" , "PYTHON_9.3")
answered Nov 22, 2013 at 17:15
2
  • Thank you for the response! I was able to -briefly- get your post to work, but when I tried to integrate the script into a larger model it broke down and keeps giving me this error: ERROR 000539: Runtime error <class 'arcgisscripting.ExecuteError'>: ERROR 000732: Input Table: Dataset PARCEL does not exist or is not supported Failed to execute (Calculate Field). Any ideas what might be happening? Commented Nov 22, 2013 at 18:42
  • Input Table: Dataset PARCEL does not exist or is not supported Failed to execute (Calculate Field) this error means , i think that the feature class has not been found. Commented Nov 22, 2013 at 19:31

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.