Need help creating a model to get each unique value, find its duplicates within the table and only return the row with the latest date.

177
0
03-07-2024 09:21 AM
Labels (3)
Ry_T
by
New Contributor

Hello, this is my first time posting a question so sorry if my question sounds confusing! 

I am trying to create a way to get the first unique value from my input table, find its duplicates based on its ID field, and only return the row with the latest date and output it to a new table. Then I need this process to repeat for each unique value in the input table and output all the results to the same table.

Ex Input Table:

IDActivityStopDate
1a01/2020
1b07/2018
2c04/2008
2d09/2021
2e03/2014
7f10/2022
9g06/2017
9h12/2023

 

Ex Output Table:

IDActivityStopDate
1a01/2020
2d09/2021
7f10/2022
9h12/2023

 

The model I made to try and do this does not work because I am probably not using the right tools or using them in the right order...

RyTisdell_0-1709831179750.png

And here's a code snippet I tried to use from another similar post and I just changed the variables to match my data, but it did not work either. 

import arcpy
fc = "COGPWorks_ExportFeatures"
rig_number = 'CarteID'
date_field_sort = 'StopDateActual'
update_cursor = arcpy.UpdateCursor(fc, '', '', rig_number, date_field_sort)
keep_list = list()
for row in update_cursor:
    row_val = row.getValue(rig_number)
    if row_val not in keep_list:
        keep_list.append(row_val)
    elif row_val in keep_list:
        update_cursor.deleteRow(row)
    else:
        pass

 

I know how to make buffers do simple calculations but when attempting multiple tools that are dependent on each other, I get confused. I am fairly new to model builder and have little experience with coding so I do not know where to start, so any guidance will be helpful!

0 Kudos
0 Replies