# How to find Max value among Fields

5862
2
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.

Example Table ("MyVals")

 ID F1 F2 F3 F4 MX 1 1 22 13 33 2 3 2 6 55 3 6 9 5 66 4 7 7 88 77 5 9 9 9 88 6 4 77 1 99 8 22 44 12 33 9 7 5 33 1 10 9 4 5 2
Tags (2)
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)‍‍‍‍``
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)‍‍‍‍``
Highlighted
New Contributor

Hi

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