<?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: Compare values in a table based on year in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/compare-values-in-a-table-based-on-year/m-p/15185#M1179</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;OL&gt;&lt;LI&gt;Create list to hold rows to be written later&lt;/LI&gt;&lt;LI&gt;Create "previous" variable&lt;/LI&gt;&lt;LI&gt;Enter into a &lt;A href="http://resources.arcgis.com/en/help/main/10.2/index.html#//018w00000011000000"&gt;Search Cursor&lt;/A&gt;&lt;OL&gt;&lt;LI&gt;Compare current code (from search cursor) to previous value (in previous variable)&lt;OL&gt;&lt;LI&gt;If different, add to list&lt;/LI&gt;&lt;/OL&gt;&lt;/LI&gt;&lt;LI&gt;Replace previous value with current code&lt;/LI&gt;&lt;LI&gt;Move to next row&lt;/LI&gt;&lt;/OL&gt;&lt;/LI&gt;&lt;LI&gt;Create an &lt;A href="http://resources.arcgis.com/en/help/main/10.2/index.html#/InsertCursor/018w0000000t000000/"&gt;Insert Cursor&lt;/A&gt;&lt;/LI&gt;&lt;LI&gt;For each value in list, write a new row using insert cursor&lt;/LI&gt;&lt;/OL&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 16 Sep 2014 19:59:52 GMT</pubDate>
    <dc:creator>DarrenWiens2</dc:creator>
    <dc:date>2014-09-16T19:59:52Z</dc:date>
    <item>
      <title>Compare values in a table based on year</title>
      <link>https://community.esri.com/t5/python-questions/compare-values-in-a-table-based-on-year/m-p/15184#M1178</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I have an original table with values like this:&lt;BR /&gt;Line ID&amp;nbsp;&amp;nbsp;&amp;nbsp; Year&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Code&lt;BR /&gt;0001&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 2002&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 300&lt;BR /&gt;0001&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 2003&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 300&lt;BR /&gt;0001&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 2004&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 500&lt;/P&gt;&lt;P&gt;I want to find the year the code changes for each line and add that into a table that only shows the year the lines that had code changes. Example:&lt;/P&gt;&lt;P&gt;Line ID&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Year_Change&lt;BR /&gt;0001&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 2004 &lt;/P&gt;&lt;P&gt;I was thinking of creating 2 dictionary’s {LID: Year} and {LID: Code} and inserting the values into a new table like this:&lt;/P&gt;&lt;P&gt;Line ID&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Code2002&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Code2003&amp;nbsp;&amp;nbsp;&amp;nbsp; Code2004&lt;BR /&gt;0001&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 300&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 300&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 500 &lt;/P&gt;&lt;P&gt;Then using if statements, such as&lt;BR /&gt;If row[1] = row[2]&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Next&lt;BR /&gt;Elif: row[2] = row[3]&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; next&lt;/P&gt;&lt;P&gt;Else:&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Create dictionary entry {LID: YearChange} which will be inserted into a table.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I think I am in a coding rut and need fresh ideas! I’d like to work with the original table. Anyone know of another way to create a loop comparing a previous record based on a 2 variable (LID and Year) expression?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 16 Sep 2014 19:21:52 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/compare-values-in-a-table-based-on-year/m-p/15184#M1178</guid>
      <dc:creator>AmyKlug</dc:creator>
      <dc:date>2014-09-16T19:21:52Z</dc:date>
    </item>
    <item>
      <title>Re: Compare values in a table based on year</title>
      <link>https://community.esri.com/t5/python-questions/compare-values-in-a-table-based-on-year/m-p/15185#M1179</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;OL&gt;&lt;LI&gt;Create list to hold rows to be written later&lt;/LI&gt;&lt;LI&gt;Create "previous" variable&lt;/LI&gt;&lt;LI&gt;Enter into a &lt;A href="http://resources.arcgis.com/en/help/main/10.2/index.html#//018w00000011000000"&gt;Search Cursor&lt;/A&gt;&lt;OL&gt;&lt;LI&gt;Compare current code (from search cursor) to previous value (in previous variable)&lt;OL&gt;&lt;LI&gt;If different, add to list&lt;/LI&gt;&lt;/OL&gt;&lt;/LI&gt;&lt;LI&gt;Replace previous value with current code&lt;/LI&gt;&lt;LI&gt;Move to next row&lt;/LI&gt;&lt;/OL&gt;&lt;/LI&gt;&lt;LI&gt;Create an &lt;A href="http://resources.arcgis.com/en/help/main/10.2/index.html#/InsertCursor/018w0000000t000000/"&gt;Insert Cursor&lt;/A&gt;&lt;/LI&gt;&lt;LI&gt;For each value in list, write a new row using insert cursor&lt;/LI&gt;&lt;/OL&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 16 Sep 2014 19:59:52 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/compare-values-in-a-table-based-on-year/m-p/15185#M1179</guid>
      <dc:creator>DarrenWiens2</dc:creator>
      <dc:date>2014-09-16T19:59:52Z</dc:date>
    </item>
    <item>
      <title>Re: Compare values in a table based on year</title>
      <link>https://community.esri.com/t5/python-questions/compare-values-in-a-table-based-on-year/m-p/15186#M1180</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Amy, &lt;/P&gt;&lt;P&gt;I wonder whether the &lt;A href="http://resources.arcgis.com/en/help/main/10.1/index.html#//00080000001z000000" title="http://resources.arcgis.com/en/help/main/10.1/index.html#//00080000001z000000"&gt;Summary Statistics tool &lt;/A&gt;‌can help in your case.&amp;nbsp; Probably not but it sounds like something there should be a tool for.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Anyhow, in Python, I would approach this with a search cursor (or other cursor depending on how you want to store the result). The key hint is that you can sort rows before you start searching them using the sql_clause parameter of arcpy.da.SearchCursor.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;In principle, I would first initialize variables to remember the last_line_id, last_code. Then, call a search cursor on&lt;/P&gt;&lt;P&gt;the initial table, order records by Line ID Ascending, Year Ascending, and Code Ascending.&lt;/P&gt;&lt;P&gt;Loop through each row and check whether your current_line_id is the same as last_line_id and if current_code is different from last_code.&lt;/P&gt;&lt;P&gt;If the above condition it true, you know the code has changed so you have to remember that year for current_line_id.&lt;/P&gt;&lt;P&gt;Don't forget to set last_line_id = current_line_id and last_code = current_code by the end of each iteration. If current_line_id is different from last_line_id, you will want to re-initialize the last_code variable and make sure you don't count it as a fake change of code for the previous line.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;We used this approach to solve a similar problem some time ago. Maybe you can adapt the code from there: &lt;A href="https://community.esri.com/thread/104575"&gt;Python to select younger of two polygons with similar attributes&lt;/A&gt; &lt;/P&gt;&lt;P&gt;If you want some code sample specifically for your situation, please explain exactly how you want the result to be structured.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 16 Sep 2014 20:17:26 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/compare-values-in-a-table-based-on-year/m-p/15186#M1180</guid>
      <dc:creator>FilipKrál</dc:creator>
      <dc:date>2014-09-16T20:17:26Z</dc:date>
    </item>
    <item>
      <title>Re: Compare values in a table based on year</title>
      <link>https://community.esri.com/t5/python-questions/compare-values-in-a-table-based-on-year/m-p/15187#M1181</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks Filip, great idea to delete the object ID's. I modified the code link you provided and got everything to work, one minor problem.....the first record does not make it into the delete object ID list (it has nothing to compare itself to?). How can I fix this?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;

import arcpy


tbl = r"U:\Projects\Change.gdb\qryTable"


flds = ['OBJECTID', 'PLIDS', 'CYEAR', 'CNUMBER']
orderby = 'ORDER BY PLIDS, CYEAR'


objdel = []&amp;nbsp; 


last_id = None


with arcpy.da.SearchCursor(tbl, flds, "", "","", sql_clause=(None, orderby)) as sc:
&amp;nbsp;&amp;nbsp;&amp;nbsp; for row in sc:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; this_id = row[3]
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if this_id == last_id:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; this_object_id = row[0]
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; objdel.append(this_object_id)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; last_id = this_id


print objdel
del row, sc


for l in objdel:
&amp;nbsp;&amp;nbsp;&amp;nbsp; expression = "OBJECTID = %s"%(l)
&amp;nbsp;&amp;nbsp;&amp;nbsp; uc = arcpy.da.UpdateCursor(tbl, "*", where_clause=expression)
&amp;nbsp;&amp;nbsp;&amp;nbsp; for u in uc:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; uc.deleteRow()
del l

&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 10 Dec 2021 20:36:27 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/compare-values-in-a-table-based-on-year/m-p/15187#M1181</guid>
      <dc:creator>AmyKlug</dc:creator>
      <dc:date>2021-12-10T20:36:27Z</dc:date>
    </item>
    <item>
      <title>Re: Compare values in a table based on year</title>
      <link>https://community.esri.com/t5/python-questions/compare-values-in-a-table-based-on-year/m-p/15188#M1182</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Just have to use a row counter, so that on the first low, set Last_id = This_Id, something like...&lt;/P&gt;&lt;PRE __default_attr="python" __jive_macro_name="code" class="jive_macro_code jive_text_macro _jivemacro_uid_14109432873628616" jivemacro_uid="_14109432873628616"&gt;
&lt;P&gt;&lt;/P&gt;


&lt;/PRE&gt;&lt;PRE __default_attr="python" __jive_macro_name="code" class="jive_macro_code _jivemacro_uid_14109434725129577 jive_text_macro" jivemacro_uid="_14109434725129577"&gt;
&lt;P&gt;&lt;SPAN class="keyword"&gt;import arcpy&amp;nbsp; &lt;/SPAN&gt;&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;tbl = r&lt;SPAN class="string"&gt;"U:\Projects\Change.gdb\qryTable"&amp;nbsp; &lt;/SPAN&gt;&lt;/LI&gt;
&lt;LI&gt;flds = [&lt;SPAN class="string"&gt;'OBJECTID', &lt;SPAN class="string"&gt;'PLIDS'&lt;/SPAN&gt;, &lt;SPAN class="string"&gt;'CYEAR'&lt;/SPAN&gt;, &lt;SPAN class="string"&gt;'CNUMBER'&lt;/SPAN&gt;]&amp;nbsp; &lt;/SPAN&gt;&lt;/LI&gt;
&lt;LI&gt;orderby = &lt;SPAN class="string"&gt;'ORDER BY PLIDS, CYEAR'&amp;nbsp; &lt;/SPAN&gt;&lt;/LI&gt;
&lt;LI&gt;objdel = []&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/LI&gt;
&lt;LI&gt;last_id = &lt;SPAN class="special"&gt;None &lt;/SPAN&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;SPAN class="special"&gt;RowCnt = 0&lt;/SPAN&gt;&lt;/LI&gt;
&lt;LI&gt;with arcpy.da.SearchCursor(tbl, flds, "&lt;SPAN class="string"&gt;", "&lt;SPAN class="string"&gt;","&lt;/SPAN&gt;", sql_clause=(&lt;SPAN class="special"&gt;None&lt;/SPAN&gt;, orderby)) as sc:&amp;nbsp; &lt;/SPAN&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;SPAN class="keyword"&gt;for row &lt;SPAN class="keyword"&gt;in&lt;/SPAN&gt; sc:&amp;nbsp; &lt;/SPAN&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;SPAN class="keyword"&gt;RowCnt +=1&lt;/SPAN&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;SPAN class="keyword"&gt;&lt;/SPAN&gt;&lt;/LI&gt;
&lt;LI&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; this_id = row[&lt;SPAN class="number"&gt;3]&amp;nbsp; &lt;/SPAN&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;SPAN class="number"&gt;if RowCnt == 1:&lt;/SPAN&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;SPAN class="number"&gt;last_id = this_id&lt;/SPAN&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;SPAN class="number"&gt;else:&lt;/SPAN&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;SPAN class="keyword"&gt;if this_id == last_id:&amp;nbsp; &lt;/SPAN&gt;&lt;/LI&gt;
&lt;LI&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; this_object_id = row[&lt;SPAN class="number"&gt;0]&amp;nbsp; &lt;/SPAN&gt;&lt;/LI&gt;
&lt;LI&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; objdel.append(this_object_id)&amp;nbsp; &lt;/LI&gt;
&lt;LI&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; last_id = this_id&amp;nbsp; &lt;/LI&gt;
&lt;LI&gt;&lt;SPAN class="keyword"&gt;print objdel&amp;nbsp; &lt;/SPAN&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;SPAN class="keyword"&gt;del row, sc&amp;nbsp; &lt;/SPAN&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;SPAN class="keyword"&gt;for l &lt;SPAN class="keyword"&gt;in&lt;/SPAN&gt; objdel:&amp;nbsp; &lt;/SPAN&gt;&lt;/LI&gt;
&lt;LI&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; expression = &lt;SPAN class="string"&gt;"OBJECTID = %s"%(l)&amp;nbsp; &lt;/SPAN&gt;&lt;/LI&gt;
&lt;LI&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; uc = arcpy.da.UpdateCursor(tbl, &lt;SPAN class="string"&gt;"*", where_clause=expression)&amp;nbsp; &lt;/SPAN&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;SPAN class="keyword"&gt;for u &lt;SPAN class="keyword"&gt;in&lt;/SPAN&gt; uc:&amp;nbsp; &lt;/SPAN&gt;&lt;/LI&gt;
&lt;LI&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; uc.deleteRow()&amp;nbsp; &lt;/LI&gt;
&lt;LI&gt;&lt;SPAN class="keyword"&gt;del l&amp;nbsp; &lt;/SPAN&gt;&lt;/LI&gt;

&lt;/UL&gt;


&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Phew, still can't get this python highlighting right....&lt;/P&gt;&lt;P&gt;So the indentations are all messed up. And when I try to edit it, I see a bunch of overlapping lines.&lt;/P&gt;&lt;P&gt;Sorry.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 17 Sep 2014 08:44:56 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/compare-values-in-a-table-based-on-year/m-p/15188#M1182</guid>
      <dc:creator>NeilAyres</dc:creator>
      <dc:date>2014-09-17T08:44:56Z</dc:date>
    </item>
    <item>
      <title>Re: Compare values in a table based on year</title>
      <link>https://community.esri.com/t5/python-questions/compare-values-in-a-table-based-on-year/m-p/15189#M1183</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I should have told you I have multiple line id's (the table I posted was just a snippet) so just counting the first row will work only for the first line. Right now I am trying to figure out a way to select for only 1 line ID at a time and use the code above. No such luck yet, not sure that is the best way to go&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 17 Sep 2014 21:02:31 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/compare-values-in-a-table-based-on-year/m-p/15189#M1183</guid>
      <dc:creator>AmyKlug</dc:creator>
      <dc:date>2014-09-17T21:02:31Z</dc:date>
    </item>
    <item>
      <title>Re: Compare values in a table based on year</title>
      <link>https://community.esri.com/t5/python-questions/compare-values-in-a-table-based-on-year/m-p/15190#M1184</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;How about something like the code below?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE __default_attr="python" __jive_macro_name="code" class="jive_macro_code _jivemacro_uid_14110512020731015 jive_text_macro" jivemacro_uid="_14110512020731015" modifiedtitle="true"&gt;
&lt;P&gt;# input table (must be geodatabase to allow sorting)&lt;/P&gt;
&lt;P&gt;tbl = r'C:\TEMP\tdb.gdb\sorting'&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;# add column to record the change&lt;/P&gt;
&lt;P&gt;arcpy.management.AddField(tbl, "changed", "SHORT")&lt;/P&gt;
&lt;P&gt;orderby = 'ORDER BY line_id, theyear, thecode'&lt;/P&gt;
&lt;P&gt;last_id, last_code = None, None&lt;/P&gt;
&lt;P&gt;with arcpy.da.UpdateCursor(tbl, ['line_id', 'theyear', 'thecode', 'changed'], sql_clause=(None, orderby)) as uc:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; for row in uc:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; this_id, this_year, this_code, changed = row&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if this_id == last_id:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if last_code != this_code:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; newrow = [this_id, this_year, this_code, 1] # change!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; uc.updateRow(newrow) #save &lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; last_id, last_code = this_id, this_code&lt;/P&gt;
&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 18 Sep 2014 14:40:42 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/compare-values-in-a-table-based-on-year/m-p/15190#M1184</guid>
      <dc:creator>FilipKrál</dc:creator>
      <dc:date>2014-09-18T14:40:42Z</dc:date>
    </item>
    <item>
      <title>Re: Compare values in a table based on year</title>
      <link>https://community.esri.com/t5/python-questions/compare-values-in-a-table-based-on-year/m-p/15191#M1185</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Brilliant! Thanks&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 18 Sep 2014 18:01:52 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/compare-values-in-a-table-based-on-year/m-p/15191#M1185</guid>
      <dc:creator>AmyKlug</dc:creator>
      <dc:date>2014-09-18T18:01:52Z</dc:date>
    </item>
  </channel>
</rss>

