Help Calculate field based on values in another field

08-31-2011 03:11 PM
Occasional Contributor
Sorry to drop this on the community, but i can't seem to find a suitable example

My target field is ???PRG_Parcel???.
I???m trying to write a function called ???answer??? that will return text to ???PRG_Parcel??? based on values in the ???Taxable??? field.

Input Table: table
Field Name: Field_Name
Expression: answer()
Exp. type: Python
Code Block:
def answer(!Taxable!)
  if Taxable > 20000:
    return "'Y'"
    return "'N'"

I've tried to do things a few different ways. Would anyone be so kind as to explain how I should be writing this code?

Thanks a bundle.

Tags (2)
0 Kudos
3 Replies
MVP Esteemed Contributor
Did you check out the pictoral image in this link down in the "Code Blocks" section?
It will visually give you an idea what needs to go where.  Also, there is no indentation in your example ensure that you are using proper indentation ( 2 or 4 spaces) in the def
0 Kudos
Occasional Contributor III
You are pretty close. What you had wrong:

  1. The expression needs to pass the field to the code block, so the field (or fields) must go in the brackets there.

  2. The term inside the code block doesn't need to have the same name as the field, or have exclamation marks around it...

The following ought to work:

Code Block:
def answer(Tx):
    if Tx > 20000:
        return "'Y'"
        return "'N'"
0 Kudos
Occasional Contributor
Exactly the help I was looking for. This helps me with a lot of different things I've been working on.

Thank you!!

The visual examples are okay, but as someone who already knows how to program, you may not notice that none of these examples explicitly detail what the variables are describing.
The code was indented properly, it was just dropped in the forums text box.
Thanks for your input though.

Thanks ESRI forums!

0 Kudos