Suppose I have a attribute table as shown in the image below:

enter image description here

I have columns A and B with common FID. I would like to add a new column C, which contains the values of column A with the condition that if the value is equal to 25 in that column, then for those rows, the value should be assigned from column B.

The highlighted green color column C in the image is how the result should look like.

Is there a tool to do this or does an expression have to be used?

4 Answers 4


Python has ternary conditional operator:

!B! if !A! == 25 else !A!
  • @nish, to get more information about a shortcut conditional expression, please check this link.
    – Taras
    Commented Dec 5, 2018 at 6:51
  • 1
    Simplest the best, no pre-logic script, no argument ordering.
    – fatih_dur
    Commented Dec 5, 2018 at 8:03

You can use Field Calculator using Python Parser:

enter image description here

in the Pre-Logic Script write the following code:

def getValue(f1,f2):
    if f1 == 25:
        return f2
        return f1


getValue(!A! , !B!)

You can use Field Calculator (see examples here) or the da.UpdateCursor like below. Change input and field names and execute in the python window of ArcMap.

import arcpy

fc = r'C:\data.gdb\feature_class' #Change to match your data
fields = ['A','B','C'] #Change to match your data

with arcpy.da.UpdateCursor(fc,fields) as cursor:
    for row in cursor:
        if row[0] == 25:
            row[2] = row[1]
            row[2] = row[0]
  • 1
    Thank you. But i wasn't sure where to input this code.
    – nish
    Commented Dec 5, 2018 at 6:43

In the Field Calculator with a usage of Python parser, please type

Pre-Logic Script Code:

def CalcColumn(fieldA, fieldB):
  if fieldA == 25:
    return fieldB
    return fieldA

C =

CalcColumn(!A!, !B!)



Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.