<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic label related data, and count results in ArcGIS Pro Questions</title>
    <link>https://community.esri.com/t5/arcgis-pro-questions/label-related-data-and-count-results/m-p/1228238#M61845</link>
    <description>&lt;P&gt;I have used the label expression 'Label a related table' (one-to many) and it works just fine, but I would like to go one step further and 'count' repited values in the resulted label.&lt;/P&gt;&lt;P&gt;I just can't seem to figure out how to write it with python...&lt;/P&gt;&lt;PRE&gt;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"&amp;lt;path-to-related-table&amp;gt;"   # Path to related table
    
    cur = arcpy.da.SearchCursor(myDataTable, [key2, L2])
    for row in cur:
        if str(key1) == str(row[0]): 
            L = L + " " + str(&lt;FONT color="#000000"&gt;&lt;STRONG&gt;row[1]&lt;/STRONG&gt;)&lt;/FONT&gt;
    return L&lt;/PRE&gt;&lt;P&gt;So the idea is to count &lt;FONT color="#000000"&gt;&lt;STRONG&gt;row[1]&lt;/STRONG&gt;&lt;/FONT&gt;, for expample if there is 4 relations where the resulted label is "&lt;EM&gt;red red red green&lt;/EM&gt;", I would like to show: "&lt;EM&gt;3 red, 1 green"&amp;nbsp;&lt;/EM&gt;.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is this possible?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 03 Nov 2022 10:05:00 GMT</pubDate>
    <dc:creator>AileYG</dc:creator>
    <dc:date>2022-11-03T10:05:00Z</dc:date>
    <item>
      <title>label related data, and count results</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/label-related-data-and-count-results/m-p/1228238#M61845</link>
      <description>&lt;P&gt;I have used the label expression 'Label a related table' (one-to many) and it works just fine, but I would like to go one step further and 'count' repited values in the resulted label.&lt;/P&gt;&lt;P&gt;I just can't seem to figure out how to write it with python...&lt;/P&gt;&lt;PRE&gt;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"&amp;lt;path-to-related-table&amp;gt;"   # Path to related table
    
    cur = arcpy.da.SearchCursor(myDataTable, [key2, L2])
    for row in cur:
        if str(key1) == str(row[0]): 
            L = L + " " + str(&lt;FONT color="#000000"&gt;&lt;STRONG&gt;row[1]&lt;/STRONG&gt;)&lt;/FONT&gt;
    return L&lt;/PRE&gt;&lt;P&gt;So the idea is to count &lt;FONT color="#000000"&gt;&lt;STRONG&gt;row[1]&lt;/STRONG&gt;&lt;/FONT&gt;, for expample if there is 4 relations where the resulted label is "&lt;EM&gt;red red red green&lt;/EM&gt;", I would like to show: "&lt;EM&gt;3 red, 1 green"&amp;nbsp;&lt;/EM&gt;.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is this possible?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 03 Nov 2022 10:05:00 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/label-related-data-and-count-results/m-p/1228238#M61845</guid>
      <dc:creator>AileYG</dc:creator>
      <dc:date>2022-11-03T10:05:00Z</dc:date>
    </item>
    <item>
      <title>Re: label related data, and count results</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/label-related-data-and-count-results/m-p/1228242#M61846</link>
      <description>&lt;LI-CODE lang="python"&gt;def FindLabel ( [GewässerID] , [OBJECTID]):
    import arcpy
    key_val = [GewässerID]
    label_1 = [OBJECTID]
    rel_table =  'path:/to/related/table'
    rel_key_field = "GewässerID"
    rel_label_field = "SegmentTyp"
    where = f"{rel_key_field} = {key_val}"
    rel_values = [r[0] for r in arcpy.da.SearchCursor(rel_table, [rel_label_field], where)]
    distinct = list(set(rel_values))
    numbers = [rel_values.count(d) for d in sorted(distinct)]
    label_2 = ", ".join([f"{n} {v}" for n, v in zip(numbers, distinct)])
    return f"{label_1}: {label_2}"
    &lt;/LI-CODE&gt;</description>
      <pubDate>Thu, 03 Nov 2022 10:37:43 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/label-related-data-and-count-results/m-p/1228242#M61846</guid>
      <dc:creator>JohannesLindner</dc:creator>
      <dc:date>2022-11-03T10:37:43Z</dc:date>
    </item>
    <item>
      <title>Re: label related data, and count results</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/label-related-data-and-count-results/m-p/1228647#M61884</link>
      <description>&lt;P&gt;Thanks for your your answer!&amp;nbsp;&lt;/P&gt;&lt;P&gt;Though it's not working quite as expected, since the function list(set(rel_values)) it separating the words into letters, and in the end counting the letter for each word...&amp;nbsp; any suggestion on how I can fix that?&lt;/P&gt;&lt;P&gt;I have&amp;nbsp; sadly very limited experience with python...&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="AileYG_0-1667545331286.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/55265iA5B6937593D7C5D1/image-size/medium?v=v2&amp;amp;px=400" role="button" title="AileYG_0-1667545331286.png" alt="AileYG_0-1667545331286.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 04 Nov 2022 07:03:20 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/label-related-data-and-count-results/m-p/1228647#M61884</guid>
      <dc:creator>AileYG</dc:creator>
      <dc:date>2022-11-04T07:03:20Z</dc:date>
    </item>
    <item>
      <title>Re: label related data, and count results</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/label-related-data-and-count-results/m-p/1228650#M61886</link>
      <description>&lt;P&gt;Hmm, it worked for my test data. Can you post your related table (the actual table or a screenshot of the label field)&lt;/P&gt;</description>
      <pubDate>Fri, 04 Nov 2022 07:40:40 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/label-related-data-and-count-results/m-p/1228650#M61886</guid>
      <dc:creator>JohannesLindner</dc:creator>
      <dc:date>2022-11-04T07:40:40Z</dc:date>
    </item>
    <item>
      <title>Re: label related data, and count results</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/label-related-data-and-count-results/m-p/1228665#M61889</link>
      <description>&lt;P&gt;I can see the logic in it... but it is not working on my data.&lt;BR /&gt;I can't post the table, but the label field is just text with values 'Inde' or 'Ude'.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="AileYG_0-1667559202047.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/55270i2D38B1CD13CEB36D/image-size/medium?v=v2&amp;amp;px=400" role="button" title="AileYG_0-1667559202047.png" alt="AileYG_0-1667559202047.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;I have also tried to use .count('Inde') values, and the result is still a separated list like "1, 1 ,0, 1" ...&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you very much for the help! It gave me some ideas to keep testing..&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 04 Nov 2022 10:57:20 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/label-related-data-and-count-results/m-p/1228665#M61889</guid>
      <dc:creator>AileYG</dc:creator>
      <dc:date>2022-11-04T10:57:20Z</dc:date>
    </item>
  </channel>
</rss>

