<?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: Arcade Expression to Calculate Field based on a Sort Date field in ArcGIS Pro Questions</title>
    <link>https://community.esri.com/t5/arcgis-pro-questions/arcade-expression-to-calculate-field-based-on-a/m-p/1293058#M69557</link>
    <description>&lt;P&gt;Good Moring Johannes,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here is a some data that is in my table for an example&lt;/P&gt;&lt;TABLE width="322"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD width="73"&gt;SiteName&lt;/TD&gt;&lt;TD width="64"&gt;UID&lt;/TD&gt;&lt;TD width="121"&gt;SampleDate&lt;/TD&gt;&lt;TD width="64"&gt;Cl&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Lab Site 1&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;2021-01-01 5:00:00&lt;/TD&gt;&lt;TD&gt;1.8&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Lab Site 2&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;2021-01-01 5:00:00&lt;/TD&gt;&lt;TD&gt;1.6&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Lab Site 3&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;2021-01-01 5:00:00&lt;/TD&gt;&lt;TD&gt;1.8&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Lab Site 4&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;2021-01-01 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lab Site 12&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;2021-01-01 5:00:00&lt;/TD&gt;&lt;TD&gt;2.5&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;</description>
    <pubDate>Thu, 25 May 2023 14:15:04 GMT</pubDate>
    <dc:creator>BrianHumphries1</dc:creator>
    <dc:date>2023-05-25T14:15:04Z</dc:date>
    <item>
      <title>Arcade Expression to Calculate Field based on a Sort Date field</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/arcade-expression-to-calculate-field-based-on-a/m-p/1292737#M69512</link>
      <description>&lt;P&gt;hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am trying to use the&amp;nbsp;SequentialNumber() for Calculate Field but I would like to calculate the Field based on the a field called&amp;nbsp; SampleDate in ascending order.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have tried using the helpers and modify the code block but failed.&lt;/P&gt;&lt;P&gt;i tried a arcade expression(below) but got null values as retuned values&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="c"&gt;// Arcade  for SequentialNumber
var rec = 0;

function SequentialNumber() {
    var pStart = 1;
    var pInterval = 1;
    var SampleDate = $feature.SampleDate;  // Name of the field used for sorting
    
    // Access the global feature set
    var Opp_table = FeatureSetByName($datastore, 'SDEP.SDEADMIN.WaterSampleInspectionsOperator');

    // Sort the features based on "SampleDate" field
    var sortedFeatures = Sort(Opp_table, SampleDate, 'ASC');
    
    if (rec == 0) {
        rec = pStart;
    } else {
        rec = rec + pInterval;
    }
    
    // Assign the sequential number based on the sorted order
    return rec;
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any help would be much appreciated&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 24 May 2023 18:51:15 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/arcade-expression-to-calculate-field-based-on-a/m-p/1292737#M69512</guid>
      <dc:creator>BrianHumphries1</dc:creator>
      <dc:date>2023-05-24T18:51:15Z</dc:date>
    </item>
    <item>
      <title>Re: Arcade Expression to Calculate Field based on a Sort Date field</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/arcade-expression-to-calculate-field-based-on-a/m-p/1292751#M69517</link>
      <description>&lt;P&gt;This should work as long as you don't have exactly the same dates in multiple rows:&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;var sd = $feature.SampleDate
return Count(Filter($featureset, "SampleDate &amp;lt; &lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/54948"&gt;@SD&lt;/a&gt;")) + 1&lt;/LI-CODE&gt;</description>
      <pubDate>Wed, 24 May 2023 19:06:23 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/arcade-expression-to-calculate-field-based-on-a/m-p/1292751#M69517</guid>
      <dc:creator>JohannesLindner</dc:creator>
      <dc:date>2023-05-24T19:06:23Z</dc:date>
    </item>
    <item>
      <title>Re: Arcade Expression to Calculate Field based on a Sort Date field</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/arcade-expression-to-calculate-field-based-on-a/m-p/1292753#M69518</link>
      <description>&lt;P&gt;I do have dates that are identical.&lt;span class="lia-unicode-emoji" title=":grimacing_face:"&gt;😬&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 24 May 2023 19:09:59 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/arcade-expression-to-calculate-field-based-on-a/m-p/1292753#M69518</guid>
      <dc:creator>BrianHumphries1</dc:creator>
      <dc:date>2023-05-24T19:09:59Z</dc:date>
    </item>
    <item>
      <title>Re: Arcade Expression to Calculate Field based on a Sort Date field</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/arcade-expression-to-calculate-field-based-on-a/m-p/1292763#M69520</link>
      <description>&lt;LI-CODE lang="javascript"&gt;var sd = $feature.DateField1
var oid = $feature.OBJECTID

var previous = Filter($featureset, "DateField1 &amp;lt; &lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/54948"&gt;@SD&lt;/a&gt;")
var same_lower = Filter($featureset, "DateField1 = &lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/54948"&gt;@SD&lt;/a&gt; AND OBJECTID &amp;lt; @oid")
return Count(previous) + Count(same_lower) + 1&lt;/LI-CODE&gt;</description>
      <pubDate>Wed, 24 May 2023 19:25:22 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/arcade-expression-to-calculate-field-based-on-a/m-p/1292763#M69520</guid>
      <dc:creator>JohannesLindner</dc:creator>
      <dc:date>2023-05-24T19:25:22Z</dc:date>
    </item>
    <item>
      <title>Re: Arcade Expression to Calculate Field based on a Sort Date field</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/arcade-expression-to-calculate-field-based-on-a/m-p/1292806#M69525</link>
      <description>&lt;P&gt;Maybe I am not setting this up correctly, I'm still getting null values... The field I am trying to calculate is a LONG field will this cause an issue with the expression?&lt;/P&gt;&lt;P&gt;This is what I used is this correct in what you suggested?&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="c"&gt;// Arcade  for SequentialNumber
var rec = 0;

function SequentialNumber() {
    var pStart = 1;
    var pInterval = 1;
    var SampleDate = $feature.SampleDate;  // Name of the field used for sorting
    var sd = $feature.SampleDate
    var oid = $feature.OBJECTID
    var previous = Filter($featureset, "$feature.SampleDate &amp;lt; ")
    var same_lower = Filter($featureset, "$feature.SampleDate =  AND OBJECTID &amp;lt; @oid")
    
    // Access the global feature set
    var Opp_table = FeatureSetByName($datastore, 'SDEP.SDEADMIN.WaterSampleInspectionsOperator');

    // Sort the features based on "SampleDate" field
    var sortedFeatures = Sort(Opp_table, SampleDate, 'ASC');
    
    if (rec == 0) {
        rec = pStart;
    } else {
        rec = rec + pInterval;
    }
    
    // Assign the sequential number based on the sorted order
    return Count(previous) + Count(same_lower) + 1
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 24 May 2023 20:16:51 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/arcade-expression-to-calculate-field-based-on-a/m-p/1292806#M69525</guid>
      <dc:creator>BrianHumphries1</dc:creator>
      <dc:date>2023-05-24T20:16:51Z</dc:date>
    </item>
    <item>
      <title>Re: Arcade Expression to Calculate Field based on a Sort Date field</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/arcade-expression-to-calculate-field-based-on-a/m-p/1292965#M69545</link>
      <description>&lt;P&gt;No, just use my expression as it is.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="JohannesLindner_0-1685009282962.png" style="width: 999px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/71653i0CB98B1628DCA730/image-size/large?v=v2&amp;amp;px=999" role="button" title="JohannesLindner_0-1685009282962.png" alt="JohannesLindner_0-1685009282962.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 25 May 2023 10:08:24 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/arcade-expression-to-calculate-field-based-on-a/m-p/1292965#M69545</guid>
      <dc:creator>JohannesLindner</dc:creator>
      <dc:date>2023-05-25T10:08:24Z</dc:date>
    </item>
    <item>
      <title>Re: Arcade Expression to Calculate Field based on a Sort Date field</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/arcade-expression-to-calculate-field-based-on-a/m-p/1293015#M69550</link>
      <description>&lt;P&gt;Good Morning,&lt;/P&gt;&lt;P&gt;Running this Code produced this error... See Below&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="c"&gt;var sd = $feature.SampleDate
var oid = $feature.OBJECTID

var previous = Filter($featureset, "SampleDate &amp;lt; &lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/54948"&gt;@SD&lt;/a&gt;")
var same_lower = Filter($featureset, "SampleDate = &lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/54948"&gt;@SD&lt;/a&gt; AND OBJECTID &amp;lt; @oid")
return Count(previous) + Count(same_lower) + 1&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="BrianHumphries1_0-1685019436011.png" style="width: 999px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/71659i6CCE25B0BCA8A221/image-size/large?v=v2&amp;amp;px=999" role="button" title="BrianHumphries1_0-1685019436011.png" alt="BrianHumphries1_0-1685019436011.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Calculate Field&lt;BR /&gt;=====================&lt;BR /&gt;Parameters&lt;/P&gt;&lt;P&gt;Input Table Operator Inspection&lt;BR /&gt;Field Name (Existing or New) UID&lt;BR /&gt;Expression&lt;/P&gt;&lt;P&gt;var sd = $feature.SampleDate&lt;BR /&gt;var oid = $feature.OBJECTID&lt;/P&gt;&lt;P&gt;var previous = Filter($featureset, "SampleDate &amp;lt; &lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/54948"&gt;@SD&lt;/a&gt;")&lt;BR /&gt;var same_lower = Filter($featureset, "SampleDate = &lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/54948"&gt;@SD&lt;/a&gt; AND OBJECTID &amp;lt; @oid")&lt;BR /&gt;return Count(previous) + Count(same_lower) + 1&lt;/P&gt;&lt;P&gt;Expression Type ARCADE&lt;BR /&gt;Code Block&lt;BR /&gt;Updated Input Table Operator Inspection&lt;BR /&gt;Field Type TEXT&lt;BR /&gt;Enforce Domains NO_ENFORCE_DOMAINS&lt;BR /&gt;=====================&lt;BR /&gt;Messages&lt;/P&gt;&lt;P&gt;Start Time: Thursday, May 25, 2023 8:58:46 AM&lt;BR /&gt;ERROR 002717: Invalid Arcade expression, Arcade error: Failed to query statistics, Script line: 6&lt;BR /&gt;Failed to execute (CalculateField).&lt;BR /&gt;Failed at Thursday, May 25, 2023 8:58:46 AM (Elapsed Time: 0.50 seconds)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 25 May 2023 13:04:25 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/arcade-expression-to-calculate-field-based-on-a/m-p/1293015#M69550</guid>
      <dc:creator>BrianHumphries1</dc:creator>
      <dc:date>2023-05-25T13:04:25Z</dc:date>
    </item>
    <item>
      <title>Re: Arcade Expression to Calculate Field based on a Sort Date field</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/arcade-expression-to-calculate-field-based-on-a/m-p/1293058#M69557</link>
      <description>&lt;P&gt;Good Moring Johannes,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here is a some data that is in my table for an example&lt;/P&gt;&lt;TABLE width="322"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD width="73"&gt;SiteName&lt;/TD&gt;&lt;TD width="64"&gt;UID&lt;/TD&gt;&lt;TD width="121"&gt;SampleDate&lt;/TD&gt;&lt;TD width="64"&gt;Cl&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Lab Site 1&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;2021-01-01 5:00:00&lt;/TD&gt;&lt;TD&gt;1.8&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Lab Site 2&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;2021-01-01 5:00:00&lt;/TD&gt;&lt;TD&gt;1.6&lt;/TD&gt;&lt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&gt;&lt;TD&gt;2021-01-01 5:00:00&lt;/TD&gt;&lt;TD&gt;1.6&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Lab Site 11&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;2021-01-01 5:00:00&lt;/TD&gt;&lt;TD&gt;2.6&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Lab Site 12&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;2021-01-01 5:00:00&lt;/TD&gt;&lt;TD&gt;2.5&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;</description>
      <pubDate>Thu, 25 May 2023 14:15:04 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/arcade-expression-to-calculate-field-based-on-a/m-p/1293058#M69557</guid>
      <dc:creator>BrianHumphries1</dc:creator>
      <dc:date>2023-05-25T14:15:04Z</dc:date>
    </item>
    <item>
      <title>Re: Arcade Expression to Calculate Field based on a Sort Date field</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/arcade-expression-to-calculate-field-based-on-a/m-p/1293104#M69564</link>
      <description>&lt;P&gt;I have no idea why this is happening...&lt;/P&gt;&lt;P&gt;Try doing it with a Python script instead (not in the Field Calculator, in the Python Window):&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="JohannesLindner_0-1685029110652.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/71675i69620EC23AA5F861/image-size/medium?v=v2&amp;amp;px=400" role="button" title="JohannesLindner_0-1685029110652.png" alt="JohannesLindner_0-1685029110652.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;table = "TestPolygons"  # the table path or layer name
sort_field = "DateField1"  # the sort field
number_field = "IntegerField1"  # the field that will be calculated

i = 1
with arcpy.da.UpdateCursor(table, [number_field], sql_clause=[None, "ORDER BY {}".format(sort_field)]) as cursor:
    for row in cursor:
        row[0] = i
        cursor.updateRow(row)
        i += 1&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 25 May 2023 15:38:54 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/arcade-expression-to-calculate-field-based-on-a/m-p/1293104#M69564</guid>
      <dc:creator>JohannesLindner</dc:creator>
      <dc:date>2023-05-25T15:38:54Z</dc:date>
    </item>
    <item>
      <title>Re: Arcade Expression to Calculate Field based on a Sort Date field</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/arcade-expression-to-calculate-field-based-on-a/m-p/1293273#M69584</link>
      <description>&lt;P&gt;Hello Johannes,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I ran as python and received a RuntimeError..,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="BrianHumphries1_0-1685046037980.png" style="width: 999px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/71721i2D49541FB242E5F4/image-size/large?v=v2&amp;amp;px=999" role="button" title="BrianHumphries1_0-1685046037980.png" alt="BrianHumphries1_0-1685046037980.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;table = "Water Sample Inspections Operator" # the table path or layer name&lt;BR /&gt;sort_field = "SampleDate" # the sort field&lt;BR /&gt;number_field = "UID" # the field that will be calculated&lt;/P&gt;&lt;P&gt;i = 1&lt;BR /&gt;with arcpy.da.UpdateCursor(table, [number_field], sql_clause=[None, "ORDER BY {}".format(sort_field)]) as cursor:&lt;BR /&gt;for row in cursor:&lt;BR /&gt;row[0] = i&lt;BR /&gt;cursor.updateRow(row)&lt;BR /&gt;i += 1&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Traceback (most recent call last):&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;File "&amp;lt;string&amp;gt;", line 9, in &amp;lt;module&amp;gt;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;RuntimeError: Invalid parameter value passed to function [SDEP.SDEADMIN.WaterSampleInspectionsOperator]&lt;/STRONG&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 25 May 2023 20:21:17 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/arcade-expression-to-calculate-field-based-on-a/m-p/1293273#M69584</guid>
      <dc:creator>BrianHumphries1</dc:creator>
      <dc:date>2023-05-25T20:21:17Z</dc:date>
    </item>
    <item>
      <title>Re: Arcade Expression to Calculate Field based on a Sort Date field</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/arcade-expression-to-calculate-field-based-on-a/m-p/1293304#M69586</link>
      <description>&lt;P&gt;Export your table to a gdb and run either the Field Calculator or the script on that exported table. If the errors persist, I'm absolutely out of ideas.&lt;/P&gt;</description>
      <pubDate>Thu, 25 May 2023 21:26:05 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/arcade-expression-to-calculate-field-based-on-a/m-p/1293304#M69586</guid>
      <dc:creator>JohannesLindner</dc:creator>
      <dc:date>2023-05-25T21:26:05Z</dc:date>
    </item>
    <item>
      <title>Re: Arcade Expression to Calculate Field based on a Sort Date field</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/arcade-expression-to-calculate-field-based-on-a/m-p/1293500#M69613</link>
      <description>&lt;P&gt;Good morning Johannes,&lt;/P&gt;&lt;P&gt;I am able to run the Arcade expression on the table Inside of the FGDB&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="BrianHumphries1_1-1685109257706.png" style="width: 999px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/71758iCAA1E1956F7C252E/image-size/large?v=v2&amp;amp;px=999" role="button" title="BrianHumphries1_1-1685109257706.png" alt="BrianHumphries1_1-1685109257706.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;My data does have identical values for the for the sample date&amp;nbsp;&lt;/P&gt;&lt;P&gt;see below&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="BrianHumphries1_0-1685109197564.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/71757iDF9F10991074AA01/image-size/medium?v=v2&amp;amp;px=400" role="button" title="BrianHumphries1_0-1685109197564.png" alt="BrianHumphries1_0-1685109197564.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Results after running the Calculation and sorting by Sample Date&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="BrianHumphries1_3-1685109910829.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/71761i06F6EB6A00632B24/image-size/medium?v=v2&amp;amp;px=400" role="button" title="BrianHumphries1_3-1685109910829.png" alt="BrianHumphries1_3-1685109910829.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;It seems that the codeworks after the first identical values change, Then its picks up the next record count after the first set of identical records are ran through.&lt;/P&gt;&lt;P&gt;So in this example I had 4 records that matched the same sample date in ascending order ,&lt;/P&gt;&lt;P&gt;then it picked up the count of 5 after the first set of identical passed.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Getting closer to making this work.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you&amp;nbsp;Johannes for all of your help so far I would be lost with out it?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I also ran the Python to see what results I would get and received this&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="BrianHumphries1_0-1685116312463.png" style="width: 999px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/71767iDAE41FB3A50CE96E/image-size/large?v=v2&amp;amp;px=999" role="button" title="BrianHumphries1_0-1685116312463.png" alt="BrianHumphries1_0-1685116312463.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Again thank you for your support Sir.&lt;/P&gt;&lt;P&gt;Brian.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 26 May 2023 15:53:30 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/arcade-expression-to-calculate-field-based-on-a/m-p/1293500#M69613</guid>
      <dc:creator>BrianHumphries1</dc:creator>
      <dc:date>2023-05-26T15:53:30Z</dc:date>
    </item>
    <item>
      <title>Re: Arcade Expression to Calculate Field based on a Sort Date field</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/arcade-expression-to-calculate-field-based-on-a/m-p/1312743#M71501</link>
      <description>&lt;P&gt;Is there a way to do this and have the numbering restart when a new date starts?&lt;/P&gt;</description>
      <pubDate>Thu, 27 Jul 2023 18:30:27 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/arcade-expression-to-calculate-field-based-on-a/m-p/1312743#M71501</guid>
      <dc:creator>RobynSnookCCB</dc:creator>
      <dc:date>2023-07-27T18:30:27Z</dc:date>
    </item>
  </channel>
</rss>

