How to find Max value among Fields

5862
2
Jump to solution
03-13-2017 09:32 AM
Highlighted
New Contributor III

Good Day GeoNet Community,

Would like to inquire how to search among rows of a table and find the maximum value only using a selected set of fields.  For example, If the table consists of five columns ID,F1,F2,F3,F4, would want to search and find the maximum value in F2 and F4.  The maximum value would become an value in a new field, called MX.  An arcpy solution is optimal and generic case is best.

Your suggestions are much appreciated, thank you for your time.

Example Table ("MyVals")

IDF1F2F3F4MX
11221333
232655
369566
4778877
599988
6477199
822441233
975331
109452
Tags (2)
Reply
0 Kudos
1 Solution

Accepted Solutions
Highlighted
MVP Honored Contributor

If you want the max of F2 and F4, in field calculator:

max(!F2!,!F4!)

Or updateCursor (untested):

with arcpy.da.UpdateCursor(fc,['F2','F4','MX']) as cursor:
  for row in cursor:
    row[2] = max(row[0],row[1])
    cursor.updateRow(row)

View solution in original post

2 Replies
Highlighted
MVP Honored Contributor

If you want the max of F2 and F4, in field calculator:

max(!F2!,!F4!)

Or updateCursor (untested):

with arcpy.da.UpdateCursor(fc,['F2','F4','MX']) as cursor:
  for row in cursor:
    row[2] = max(row[0],row[1])
    cursor.updateRow(row)

View solution in original post

Highlighted
New Contributor

Hi 

I'm trying to apply max function but it's not working...any relation with properties??? string value?

Reply
0 Kudos