I have a shapefile containing two numeric fields ("Dist_1" and "Dist_2"). I want a Field Calculation that will populate an additional field ("Result") with one of three answers:

First if Dist_1 is greater than Dist_2 populate Result with 'True' Second if Dist_1 is less than Dist_2 populate with 'False' and Third if Dist_1 and Dist_2 are equal populate with "Equal"


1 Answer 1




Code block:

def calc(f1,f2):

    if f1 > f2:
        return "True"
    elif f1 < f2:
        return "False"
        return "Equal"


calc(!Dist_1!, !Dist_2!)

Or graphically (you cannot see all of the code block here unfortunately)

enter image description here

  • PolyGeo thanks - but getting an error 000989 - Parsing error: unindent does not match any outer indentation level (line 3). Can you decode this?!!
    – Chris U
    Sep 28, 2013 at 19:26
  • 2
    Keep consistent spacing for the if,elif,else statements (2) as well as the return statements (4). Each should be on its own line.
    – Paul
    Sep 28, 2013 at 19:44
  • 1
    Paul/PolyGeo, many thanks this works a treat!
    – Chris U
    Sep 29, 2013 at 9:14

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.