Continue in the app
Be The First To Get Support Updates
Want to know about the latest technical content and software updates?

How To: Label a related table


Instructions provided describe how to label a related table using Python. There is no 'out-of-the-box' functionality to label a related table.

A basic understanding of Python functions and search cursors is needed.


The code below creates a FindLabel Python function. Relates are never created, but the two key fields are compared in a double iteration.

  1. Open the Label Expression dialog box.
    1. Right-click the feature class to be labeled and select Properties.
    2. Click the Labels tab.
    3. Click Expression to open the Label Expression dialog box.
  2. Select Python as the parser and check the Advanced check box.
  3. Copy-paste the following code. Note that [keyfield], [FirstLabel], key1, key2, L, L2, and myDataTable must be changed to match the environment.
    • [keyfield] and key1 are the key fields in the feature class, used to relate to the related table.
    • [FirstLabel] and L are the field in the feature class to be labeled.
    • key2 is the key field in the related table.
    • L2 is the field in the related table that should also be labeled. myDataTable is the path and name of the related table.
def FindLabel ([keyField], [FirstLabel]):
    import arcpy

    key1 = [keyField] # Key field in feature class
    key2 = "ID"   # Key field in related table
    L = [FirstLabel] # Label field in feature class
    L2 = "Label2"   # Label field in related table
    myDataTable = r"<path-to-related-table>"   # Path to related table
    cur = arcpy.da.SearchCursor(myDataTable, [key2, L2])
    for row in cur:
        if str(key1) == str(row[0]): 
            L = L + " " + str(row[1])
    return L
  1. Click OK to return to the Layer Properties dialog box.
  2. Click Apply to see the labels.

Related Information

Last Published: 11/16/2021

Article ID: 000012230

Software: ArcGIS for Desktop Advanced 10.3, 10.2.2, 10.2.1, 10.2, 10.1 ArcGIS for Desktop Basic 10.3, 10.2.2, 10.2.1, 10.2, 10.1 ArcGIS for Desktop Standard 10.3, 10.2.2, 10.2.1, 10.2, 10.1