How can I create a new attribute field which has results based on a simple combination of two other string fields, except when a third field gives a certain result, in which case I would like that result to be the output rather than the combination of the other two fields?
-
Welcome to GIS SE! What version of ArcGIS Desktop are you using? Can you give an example of what's in your fields and the output you would expect in the different situations?– Midavalo ♦Mar 3, 2017 at 16:24
-
Are you asking how to create the field? Or just how to calculate it once you have the field?– Midavalo ♦Mar 3, 2017 at 16:26
-
Please edit your question when adding/updating any information– Midavalo ♦Mar 3, 2017 at 16:27
2 Answers
You could create the new text field, and then run the Field Calculator on it.
Using Python, you could do:
def combine(field1, field2, field3):
if str(field3) != "CertainValue":
return "{0}{1}".format(field1, field2)
else:
return str(field3)
So, this is saying, if the value in field3
is not equal to this CertainValue
then return field1
and field2
concatenated. Otherwise, just return the field3
value.
Then at the bottom of the Field Calculator, you'd put:
combine(!yourField1!, !yourField2!, !yourField3!)
I'm assuming that by saying result to be the output
- this is the value of the third field?
A Python script is the better way to do this but if you don't know Python and you only have two different conditions you need to deal with, you can do it manually pretty easily:
- Add the new field to your attribute table using the Add Field tool.
- Use Select by Attributes (under the Selection menu) to select the records in your table that match your "third field gives a certain result" condition.
- Use the field calculator to assign those records the value you want in the new field.
- Use Switch Selection to select the other records, which don't match your "third field gives a certain result" condition.
- Use field calculator again to assign those records the other value you want.