How do I write an expression to label the max value for a specific location?

1144
2
01-16-2020 12:17 PM
pokateo_
New Contributor III

I have a dataset with co-located points (e.g. "Site 1" has 3 rows with different numbers in the Value field). 

I need to label the site with the max value of the set (the highlighted values below).

Tags (2)
2 Replies
by Anonymous User
Not applicable

Here is a solution using python based on Label highest values and How To: Label a related table 

import arcpy
lyrName = r'path\to\layer'

def getMax(location):
    filter = f"Location_Name = '{location}'"
        
    with arcpy.da.SearchCursor(lyrName, ('Value'), where_clause=filter) as cursor:  
        max_val = max([row[0] for row in cursor])
    return(max_val)
            
            
def FindLabel ( [Location_Name] ):
    return getMax([Location_Name])‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

You use a search cursor to find the maximum of all 'Value' for the records where 'Location_Name' matches the Location_Name for the current feature. Be sure to replace the path to your layer (it must be the full path to the data on disc). Since it is reading the data from disk it will not honor things like definition queries so watch out for that. You may also want to disable duplicate labels for the layer.

JoshuaBixby
MVP Esteemed Contributor

If you end up using the techniqueElliott Kurtz‌ references/proposes, just be aware it will not perform well for large data sets, and it might not even perform well for moderate data sets.  If the data isn't changing often, I suggest you create a new column in the data set and populate with the label value rather than generating it dynamically each time the screen is refreshed.