# ArcMap Calculate Field..if "text" in !Field!

Is it possible to use Field Calculator in ArcGIS to add text to a new field based on an if in statement?

Example: In an attribute table I have a some fields called !X!, !Y!, !Z! where "A (xx%)", "B (xx%)", "C (xx%)", "D (xx%)" are the data.

The data can be found in any field but does not have to.

I would like to use python in some form so that once I have created a New Field, I can calculate `if A in !X!` copy A in !X! to New Field then continue this through !Y! and !Z!.

I believe outside of Field Calculator this will involve If in statements followed by arcpy.da.insertcursor() but I'm pretty stumped at the moment.

I hope this is clear...thanks for any help and comments!

• Would you be able to edit your Question to make it clearer what you wish to be returned from each of your if/elif/else options, please? It sounds like it should be easy to do but I would like to know what values are being input and what needs to be output/returned.
– PolyGeo
Apr 1, 2014 at 11:01

Your question is a bit unclear. I try to explain to you what this script does:

You have a `column A` and a `column B`. Depending on the values in `column A` we populate the empty fields in `Column B`.

``````change(!A!) #write that into Expression of your Field Calculator,  with the "!" you tell ArcMap in Python that this is a column

def change (A): #everything from here goes into your CodeBlock
if A == 1: #first if statement
return b
elif A == 2: #if the first if statement does not apply, then the next \"elif\" statement goes into action
return c
elif A == 3:
return d #this can be done for as many elif statements as you like
else: #if non of the if and elif statements apply, then we use the else statement to return a value for all the fields in column A where the above quoted condition DO NOT apply
return 0
``````

Make sure you chose in `Expression` Python. make also sure you get your indentation right (four spaces in front of the `if`, `elif` and `else` statement and eight spaces in front of the `return`

If you want to populate the `Column B` with a `String`, just add "" to your return values.

``````if A == 3:
return "String"
``````

Hope that helps.

• You need indentation on the `if....elif` statements. Great explanation though!
– Paul
Jul 23, 2014 at 17:53
• Ups, wrote about but did not stick to it. Ill correct it. Thank you. I try to give back. Got so much help here. With what Ive learned, I try to help others :) Jul 23, 2014 at 17:54