1

I'm attempting to calculate the values of a field based on IF THEN statements in ArcMap 10 (in field calculator) but I haven't succeeded yet on that.

What I want to add is the following expression:

IF [FIELDNAME1] = [FIELDNAME2] then

[FIELDNMCH] = "no change" else

[FIELDNMCH] = "change"

END IF

The values in the fieldnames are texts.

Any help on that?

3

The ultimate result of this calculation is a boolean typed value (i.e., True or False). ArcMap does not have a boolean type built in, but you can simulate it in one of two ways:

  1. If you are using a geodatabase, best practice would be to store the result of this calculation using an Attribute Domain that you define to your needs.

  2. If that's overkill, you should still simulate a boolean type by storing FIELDNMCH as an integer (i.e., 1 or 0 meaning True or False). This allows you to do logical operations with these values in future analyses.

In either case you could get the answer by doing the following in the Field Calculator's Python parser:

!fieldname1! == !fieldname2!

If you want a match to mean True, or,

!fieldname1! != !fieldname2!

If you want True to mean that the fields don't match.

If you are absolutely married to the idea storing FIELDNMCH as the strings 'change' and 'no change', then in Field Calculator, use the following Python codeblock:

def hasChanged(oldRecord, newRecord):
    if oldRecord == newRecord:
        return 'no change'
    else:
        return 'change'

Then, calculate:

hasChanged(!fieldname1!, !fieldname2!)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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