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")
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 |
Solved! Go to Solution.
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)
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)
Hi
I'm trying to apply max function but it's not working...any relation with properties??? string value?
I agree this doesn't seem to work and therefore should not be marked as the solution. @DarrenWiens2
This thread seems to agree: https://gis.stackexchange.com/questions/90697/how-to-populate-new-field-using-expression-containing-...
What doesn't work? Quick test seems successful:
Python cursor solution is successful, too:
Hello Stephen,
I faced a similar issue. The following code worked for me -
Max($Field1,$Field2)
Expression type - Arcade.
Regards, Kedar