Python for 'Calculate Field'

207
2
Jump to solution
04-05-2018 07:18 AM
ChrisMarsh2
New Contributor II

Hi,

I have two columns in my table: 'Join_Count' and 'SEG_Count'.

I am trying to use the 'Calculate Field' tool so that if the number in the 'SEG_Count' column is higher than the number shown in the 'Join_Count' column, calculate field will change the number in the 'SEG_Count' column to be whatever number is shown in the 'Join_Count' column; however I cannot work out the Python script to do this.

Any help would be appreciated,

Thanks in advance.

0 Kudos
1 Solution

Accepted Solutions
RichardFairhurst
MVP Honored Contributor

Do the calculation on the SEG_Count field with the following settings (I assumed that there are no Null values in these fields):

Parser: Python

Code Block: Checked

Pre-Logic Code Block

def SEG_Count_Cap(SEG_Count, Join_Count):
  if SEG_Count > Join_Count:
    return Join_Count
  else:
    return SEG_Count‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

SEG_Count:

SEG_Count_Cap(!SEG_Count!, !Join_Count!)

View solution in original post

2 Replies
RichardFairhurst
MVP Honored Contributor

Do the calculation on the SEG_Count field with the following settings (I assumed that there are no Null values in these fields):

Parser: Python

Code Block: Checked

Pre-Logic Code Block

def SEG_Count_Cap(SEG_Count, Join_Count):
  if SEG_Count > Join_Count:
    return Join_Count
  else:
    return SEG_Count‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

SEG_Count:

SEG_Count_Cap(!SEG_Count!, !Join_Count!)

ChrisMarsh2
New Contributor II

Many thanks Richard!

0 Kudos