<?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 Re: Count Duplicates in a Field for sequential unique ID in ArcMap Questions</title>
    <link>https://community.esri.com/t5/arcmap-questions/count-duplicates-in-a-field-for-sequential-unique/m-p/1056750#M2477</link>
    <description>&lt;P&gt;Thank you so much! Is there a way for me to make this create a new field and populate it?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 11 May 2021 16:46:40 GMT</pubDate>
    <dc:creator>GabriellaSantana</dc:creator>
    <dc:date>2021-05-11T16:46:40Z</dc:date>
    <item>
      <title>Count Duplicates in a Field for sequential unique ID</title>
      <link>https://community.esri.com/t5/arcmap-questions/count-duplicates-in-a-field-for-sequential-unique/m-p/1056493#M2470</link>
      <description>&lt;P&gt;I am trying to create a unique ID for my street feature class. (My unique ID starts with first 3 letters of the Street Name, 2 letters of the Street type, and 3 letters of the City Name Abbreviated.) Where I am stuck is that I am trying to get a number to increment on the segments that would be duplicated. For example, Glenacre Drive has three segments. The UniqueID would be GLEDRHQF01, GLEDRHQF02, GELDRHQF03. I cant figure out how to create sequential numbers not based off of the ObjectID sorting... For example I used the following Field Calculator but realized it is looking at the ObjectID sort and my streets aren't entered in order...&lt;/P&gt;&lt;P&gt;Pre-Logic Script Code:&lt;/P&gt;&lt;P&gt;prevFieldValue = '' counter = 1 def GetDuplicateCounter(myFieldValue): global prevFieldValue global counter if myFieldValue == prevFieldValue: counter += 1 else: counter = 1 prevFieldValue = myFieldValue return counter&lt;/P&gt;&lt;P&gt;= GetDuplicateCounter( !UNIQUEID! )&lt;/P&gt;&lt;P&gt;Any Help would be Amazing! &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 10 May 2021 23:45:53 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcmap-questions/count-duplicates-in-a-field-for-sequential-unique/m-p/1056493#M2470</guid>
      <dc:creator>GabriellaSantana</dc:creator>
      <dc:date>2021-05-10T23:45:53Z</dc:date>
    </item>
    <item>
      <title>Re: Count Duplicates in a Field for sequential unique ID</title>
      <link>https://community.esri.com/t5/arcmap-questions/count-duplicates-in-a-field-for-sequential-unique/m-p/1056577#M2471</link>
      <description>&lt;P&gt;Define a dictionary that relates the string part of the id to the corresponding counter:&lt;/P&gt;&lt;LI-CODE lang="python"&gt;duplicates = {"GLEDRHQF": 3}

def get_duplicate_counter(value):
    try:
        counter = duplicates[value] + 1
    except KeyError:
        counter = 1
    duplicates[value] = counter
    return counter
    # or directly return the complete id:
    # return "{}{:02d}".format(value, counter)&lt;/LI-CODE&gt;</description>
      <pubDate>Tue, 11 May 2021 07:46:43 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcmap-questions/count-duplicates-in-a-field-for-sequential-unique/m-p/1056577#M2471</guid>
      <dc:creator>JohannesLindner</dc:creator>
      <dc:date>2021-05-11T07:46:43Z</dc:date>
    </item>
    <item>
      <title>Re: Count Duplicates in a Field for sequential unique ID</title>
      <link>https://community.esri.com/t5/arcmap-questions/count-duplicates-in-a-field-for-sequential-unique/m-p/1056670#M2474</link>
      <description>&lt;P&gt;Something like this should work in the interactive Python window:&lt;/P&gt;&lt;LI-CODE lang="python"&gt;lyr = # name of layer or path to data set

with arcpy.da.UpdateCursor(lyr, "UNIQUEID", sql_clause=(None, "ORDER BY UNIQUEID")) as cur:
    cnt = 1
    uid, = next(cur)
    cur.updateRow(["{}{:02}".format(uid,cnt)])
    uid_prev = uid
    for uid, in cur:
        if uid == uid_prev:
            cnt += 1
        else:
            cnt = 1
        
        cur.updateRow(["{}{:02}".format(uid,cnt)])
        uid_prev = uid
    &lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 11 May 2021 13:56:39 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcmap-questions/count-duplicates-in-a-field-for-sequential-unique/m-p/1056670#M2474</guid>
      <dc:creator>JoshuaBixby</dc:creator>
      <dc:date>2021-05-11T13:56:39Z</dc:date>
    </item>
    <item>
      <title>Re: Count Duplicates in a Field for sequential unique ID</title>
      <link>https://community.esri.com/t5/arcmap-questions/count-duplicates-in-a-field-for-sequential-unique/m-p/1056750#M2477</link>
      <description>&lt;P&gt;Thank you so much! Is there a way for me to make this create a new field and populate it?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 11 May 2021 16:46:40 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcmap-questions/count-duplicates-in-a-field-for-sequential-unique/m-p/1056750#M2477</guid>
      <dc:creator>GabriellaSantana</dc:creator>
      <dc:date>2021-05-11T16:46:40Z</dc:date>
    </item>
    <item>
      <title>Re: Count Duplicates in a Field for sequential unique ID</title>
      <link>https://community.esri.com/t5/arcmap-questions/count-duplicates-in-a-field-for-sequential-unique/m-p/1056967#M2479</link>
      <description>&lt;P&gt;Just use &lt;A href="https://desktop.arcgis.com/en/arcmap/latest/tools/data-management-toolbox/add-field.htm" target="_blank"&gt;Add Field (Data Management)—ArcMap | Documentation (arcgis.com)&lt;/A&gt; upstream of the code snippet I provided, and then adjust the cursor to work with the necessary fields.&lt;/P&gt;</description>
      <pubDate>Wed, 12 May 2021 01:36:43 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcmap-questions/count-duplicates-in-a-field-for-sequential-unique/m-p/1056967#M2479</guid>
      <dc:creator>JoshuaBixby</dc:creator>
      <dc:date>2021-05-12T01:36:43Z</dc:date>
    </item>
    <item>
      <title>Re: Count Duplicates in a Field for sequential unique ID</title>
      <link>https://community.esri.com/t5/arcmap-questions/count-duplicates-in-a-field-for-sequential-unique/m-p/1057202#M2482</link>
      <description>&lt;P&gt;Thank you!!&lt;/P&gt;</description>
      <pubDate>Wed, 12 May 2021 16:19:42 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcmap-questions/count-duplicates-in-a-field-for-sequential-unique/m-p/1057202#M2482</guid>
      <dc:creator>GabriellaSantana</dc:creator>
      <dc:date>2021-05-12T16:19:42Z</dc:date>
    </item>
  </channel>
</rss>

