Skip to main content
Added additional scenario for a question asked in a comment
Source Link
Jason Miller
  • 1.5k
  • 1
  • 12
  • 25

This answer is essentially the same as listed above, however it's a way to not have to use the code block... for the Count01 field, you would set the parser to Python and then set your calculation to

1 if !YEAR! == 2001 else 0

The way this reads is: Set the field to 1 if the YEAR field is 2001, if it's not 2001, then set it to 0...

If you have multiple if conditions, you can nest the 2nd (and subsequent) "if" conditions inside the else statement, such as this...

1 if !YEAR! == 2001 else (2 if !YEAR! == 2002 else 0)

The way this reads is: Set the field to 1 if the YEAR field is 2001, if it's not 2001, then set it to 2 if it's 2002, if not, then set it to 0...

This answer is essentially the same as listed above, however it's a way to not have to use the code block... for the Count01 field, you would set the parser to Python and then set your calculation to

1 if !YEAR! == 2001 else 0

The way this reads is: Set the field to 1 if the YEAR field is 2001, if it's not 2001, then set it to 0...

This answer is essentially the same as listed above, however it's a way to not have to use the code block... for the Count01 field, you would set the parser to Python and then set your calculation to

1 if !YEAR! == 2001 else 0

The way this reads is: Set the field to 1 if the YEAR field is 2001, if it's not 2001, then set it to 0...

If you have multiple if conditions, you can nest the 2nd (and subsequent) "if" conditions inside the else statement, such as this...

1 if !YEAR! == 2001 else (2 if !YEAR! == 2002 else 0)

The way this reads is: Set the field to 1 if the YEAR field is 2001, if it's not 2001, then set it to 2 if it's 2002, if not, then set it to 0...

Source Link
Jason Miller
  • 1.5k
  • 1
  • 12
  • 25

This answer is essentially the same as listed above, however it's a way to not have to use the code block... for the Count01 field, you would set the parser to Python and then set your calculation to

1 if !YEAR! == 2001 else 0

The way this reads is: Set the field to 1 if the YEAR field is 2001, if it's not 2001, then set it to 0...