<?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: Field Calc Sequential Number based on another column in Geoprocessing Questions</title>
    <link>https://community.esri.com/t5/geoprocessing-questions/field-calc-sequential-number-based-on-another/m-p/657738#M21923</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Update: Using this python script I was able to have it count properly and populate the needed column. I guess now I just need to know how to set it to have 4 digits with leading 0's (ie 0001 instead of 1, or 0110 instead of 110). Any suggestions?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="color: #000000; margin: 0in; font-size: 11.0pt;"&gt;tbl = r'C:\my\data.gdb\table'&lt;/P&gt;&lt;P style="color: #000000; margin: 0in; font-size: 11.0pt;"&gt;data_dict = defaultdict(int)&lt;/P&gt;&lt;P style="color: #000000; margin: 0in; font-size: 11.0pt;"&gt;with arcpy.da.UpdateCursor(tbl, ["Level3Name", "Level4Code"]) as cur:&lt;/P&gt;&lt;P style="color: #000000; margin: 0in; font-size: 11.0pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; for uniq, code in cur:&lt;/P&gt;&lt;P style="color: #000000; margin: 0in; font-size: 11.0pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; data_dict[uniq] += 1&lt;/P&gt;&lt;P style="color: #000000; margin: 0in; font-size: 11.0pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; cur.updateRow([uniq, data_dict[uniq]])&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 13 Oct 2020 20:23:05 GMT</pubDate>
    <dc:creator>BrandenHarding</dc:creator>
    <dc:date>2020-10-13T20:23:05Z</dc:date>
    <item>
      <title>Field Calc Sequential Number based on another column</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/field-calc-sequential-number-based-on-another/m-p/657737#M21922</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I need to populate a column (Level4Code) with the field calculator that counts sequentially based on another column (Level3Name) and includes 4 digits. Here is an example of a table that's already populated correctly:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;TABLE class="j-table jiveBorder" style="border: 1px solid #c6c6c6;" width="100%"&gt;&lt;THEAD&gt;&lt;TR style="background-color: #efefef;"&gt;&lt;TH&gt;Level3Name&lt;/TH&gt;&lt;TH&gt;Level4Code&lt;/TH&gt;&lt;/TR&gt;&lt;/THEAD&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;Adilabad&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;0001&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;SPAN&gt;Adilabad&lt;/SPAN&gt;&lt;/TD&gt;&lt;TD&gt;0002&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;SPAN&gt;Adilabad&lt;/SPAN&gt;&lt;/TD&gt;&lt;TD&gt;0003&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Agar Malwa&lt;/TD&gt;&lt;TD&gt;0001&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;SPAN&gt;Agar Malwa&lt;/SPAN&gt;&lt;/TD&gt;&lt;TD&gt;0002&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Agra&lt;/TD&gt;&lt;TD&gt;0001&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Agra&lt;/TD&gt;&lt;TD&gt;0002&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The out of the box sequential code does not do it correctly since it doesn't loop based on any other column.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;So far, I've&amp;nbsp;tried this code snippet to count but I am not getting the results I need. This only seems to count the total number of times that word in Level3Name is present:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;OL class="" start="1" style="color: #5c5c5c; background-color: #ffffff; border: none; font-size: 12px; margin: 0px 0px 1px 45px !important;"&gt;&lt;LI class="" style="color: inherit; background-color: #ffffff; border-top: none; border-bottom: none; border-left: 3px solid #6ce26c; border-right: none; font-weight: inherit; font-size: 12px; margin: 0px !important; padding: 0px 3px 0px 10px !important;"&gt;&lt;SPAN style="color: black; background-color: inherit; border: 0px; font-weight: inherit; font-size: 9pt !important;"&gt;dict&amp;nbsp;=&amp;nbsp;{}&amp;nbsp;&lt;SPAN class="" style="color: green; background-color: inherit; border: 0px; font-weight: inherit; font-size: 9pt !important;"&gt;#&amp;nbsp;make&amp;nbsp;a&amp;nbsp;dictionary&lt;/SPAN&gt;&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;/LI&gt;&lt;LI class="" style="color: #5c5c5c; background-color: #f6f6f6; border-top: none; border-bottom: none; border-left: 3px solid #6ce26c; border-right: none; font-weight: inherit; font-size: 12px; margin: 0px !important; padding: 0px 3px 0px 10px !important;"&gt;&lt;SPAN style="color: black; background-color: inherit; border: 0px; font-weight: inherit; font-size: 9pt !important;"&gt;&lt;SPAN class="" style="color: #0088e1; background-color: inherit; border: 0px; font-weight: inherit; font-size: 9pt !important;"&gt;def&lt;/SPAN&gt;&amp;nbsp;myFunc(myClass):&amp;nbsp;&lt;SPAN class="" style="color: green; background-color: inherit; border: 0px; font-weight: inherit; font-size: 9pt !important;"&gt;#&amp;nbsp;this&amp;nbsp;is&amp;nbsp;the&amp;nbsp;function&lt;/SPAN&gt;&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;/LI&gt;&lt;LI class="" style="color: inherit; background-color: #ffffff; border-top: none; border-bottom: none; border-left: 3px solid #6ce26c; border-right: none; font-weight: inherit; font-size: 12px; margin: 0px !important; padding: 0px 3px 0px 10px !important;"&gt;&lt;SPAN style="color: black; background-color: inherit; border: 0px; font-weight: inherit; font-size: 9pt !important;"&gt;&amp;nbsp;&amp;nbsp;&lt;SPAN class="" style="color: #0088e1; background-color: inherit; border: 0px; font-weight: inherit; font-size: 9pt !important;"&gt;global&lt;/SPAN&gt;&amp;nbsp;dict&amp;nbsp;&lt;SPAN class="" style="color: green; background-color: inherit; border: 0px; font-weight: inherit; font-size: 9pt !important;"&gt;#&amp;nbsp;specify&amp;nbsp;global&lt;/SPAN&gt;&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;/LI&gt;&lt;LI class="" style="color: #5c5c5c; background-color: #f6f6f6; border-top: none; border-bottom: none; border-left: 3px solid #6ce26c; border-right: none; font-weight: inherit; font-size: 12px; margin: 0px !important; padding: 0px 3px 0px 10px !important;"&gt;&lt;SPAN style="color: black; background-color: inherit; border: 0px; font-weight: inherit; font-size: 9pt !important;"&gt;&amp;nbsp;&amp;nbsp;dict[myClass]&amp;nbsp;=&amp;nbsp;dict.get(myClass,&amp;nbsp;&lt;SPAN class="" style="color: green; background-color: inherit; border: 0px; font-weight: inherit; font-size: 9pt !important;"&gt;0&lt;/SPAN&gt;)&amp;nbsp;+&amp;nbsp;&lt;SPAN class="" style="color: green; background-color: inherit; border: 0px; font-weight: inherit; font-size: 9pt !important;"&gt;1&lt;/SPAN&gt;&amp;nbsp;&lt;SPAN class="" style="color: green; background-color: inherit; border: 0px; font-weight: inherit; font-size: 9pt !important;"&gt;#&amp;nbsp;if&amp;nbsp;the&amp;nbsp;dictionary&amp;nbsp;key&amp;nbsp;for&amp;nbsp;the&amp;nbsp;value&amp;nbsp;exists,&amp;nbsp;add&amp;nbsp;1&amp;nbsp;to&amp;nbsp;it.&amp;nbsp;If&amp;nbsp;not,&amp;nbsp;make&amp;nbsp;it&amp;nbsp;0.&lt;/SPAN&gt;&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;/LI&gt;&lt;LI class="" style="color: inherit; background-color: #ffffff; border-top: none; border-bottom: none; border-left: 3px solid #6ce26c; border-right: none; font-weight: inherit; font-size: 12px; margin: 0px !important; padding: 0px 3px 0px 10px !important;"&gt;&lt;SPAN style="color: black; background-color: inherit; border: 0px; font-weight: inherit; font-size: 9pt !important;"&gt;&amp;nbsp;&amp;nbsp;&lt;SPAN class="" style="color: #0088e1; background-color: inherit; border: 0px; font-weight: inherit; font-size: 9pt !important;"&gt;return&lt;/SPAN&gt;&amp;nbsp;dict[myClass]&amp;nbsp;&lt;SPAN class="" style="color: green; background-color: inherit; border: 0px; font-weight: inherit; font-size: 9pt !important;"&gt;#&amp;nbsp;return&amp;nbsp;the&amp;nbsp;value&amp;nbsp;for&amp;nbsp;that&amp;nbsp;key&lt;/SPAN&gt;&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;/LI&gt;&lt;/OL&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Any suggestions? I am new to Python so any help would be great.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 13 Oct 2020 14:50:24 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/field-calc-sequential-number-based-on-another/m-p/657737#M21922</guid>
      <dc:creator>BrandenHarding</dc:creator>
      <dc:date>2020-10-13T14:50:24Z</dc:date>
    </item>
    <item>
      <title>Re: Field Calc Sequential Number based on another column</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/field-calc-sequential-number-based-on-another/m-p/657738#M21923</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Update: Using this python script I was able to have it count properly and populate the needed column. I guess now I just need to know how to set it to have 4 digits with leading 0's (ie 0001 instead of 1, or 0110 instead of 110). Any suggestions?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="color: #000000; margin: 0in; font-size: 11.0pt;"&gt;tbl = r'C:\my\data.gdb\table'&lt;/P&gt;&lt;P style="color: #000000; margin: 0in; font-size: 11.0pt;"&gt;data_dict = defaultdict(int)&lt;/P&gt;&lt;P style="color: #000000; margin: 0in; font-size: 11.0pt;"&gt;with arcpy.da.UpdateCursor(tbl, ["Level3Name", "Level4Code"]) as cur:&lt;/P&gt;&lt;P style="color: #000000; margin: 0in; font-size: 11.0pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; for uniq, code in cur:&lt;/P&gt;&lt;P style="color: #000000; margin: 0in; font-size: 11.0pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; data_dict[uniq] += 1&lt;/P&gt;&lt;P style="color: #000000; margin: 0in; font-size: 11.0pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; cur.updateRow([uniq, data_dict[uniq]])&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 13 Oct 2020 20:23:05 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/field-calc-sequential-number-based-on-another/m-p/657738#M21923</guid>
      <dc:creator>BrandenHarding</dc:creator>
      <dc:date>2020-10-13T20:23:05Z</dc:date>
    </item>
    <item>
      <title>Re: Field Calc Sequential Number based on another column</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/field-calc-sequential-number-based-on-another/m-p/1002615#M24891</link>
      <description>&lt;P&gt;As you have learned, or maybe just coincidentally avoided, using Field Calculator for creating sequential numbering runs into problems if the sequencing doesn't line up with the ObjectID sequence.&lt;/P&gt;&lt;P&gt;Regarding your follow-up question, do you want to have the data stored as "000x" etc... or do you just want the formatting for a table you are looking at to be that way?&amp;nbsp; If the former, you need Level4Code to be a string field and use string formatting.&amp;nbsp; If the latter, you can create a custom number formatting for that field in the table in Pro.&lt;/P&gt;&lt;P&gt;The following should work for string formatting:&lt;/P&gt;&lt;LI-CODE lang="python"&gt;cur.updateRow([uniq, "{:0&amp;gt;4}".format(data_dict[uniq])])&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 18 Nov 2020 18:06:08 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/field-calc-sequential-number-based-on-another/m-p/1002615#M24891</guid>
      <dc:creator>JoshuaBixby</dc:creator>
      <dc:date>2020-11-18T18:06:08Z</dc:date>
    </item>
  </channel>
</rss>

