Select to view content in your preferred language

How can I field calculate sequential numbering which restart with each new day?

1068
3
Jump to solution
08-04-2020 09:20 AM
by Anonymous User
Not applicable

In my feature table I have a column labeled 'Sequence' which I would like to add sequential numbering to which resets with each new day.

example: 

Date          Sequence

8/3/2020  |      1

8/3/2020  |      2

8/3/2020  |      3

8/3/2020  |      4

8/4/2020  |      1

8/4/2020  |      2

0 Kudos
1 Solution

Accepted Solutions
JoeBorgione
MVP Emeritus

Are you looking for an automated solution to  correct a few months of sequence data?  I've done that sort of things with an update cursor:

fc = r'C:\some\path\to\your\data'
startValue = 1
fields = ['YourFieldName']
where = "A a sql select statement for a particular date'

arcpy.MakeFeatureLayer_management(fc,'fcLayer')

arcpy.SelectLayerByAttribute_management('fcLayer', 'NEW_SELECTION', where)

with arcpy.da.UpdateCursor('fcLayer',fields)as cursor:
    for row in cursor:
        row[0] = startValue
        cursor.updateRow(row)
        startValue += 1

If you have a list of dates, you could loop through it and create the where statement on the fly. I think the update cursor will update in order of object id for the selected set, but don't quote me on that.

***Untested for this particular application...

That should just about do it....

View solution in original post

3 Replies
JoeBorgione
MVP Emeritus

What product are you using?  "Traditional Desktop (10.x)" or ArcGIS Pro?

If the latter, you could write a script that deletes and then re-creates a database sequence, and run it every night at 00:00:01 hours as a scheduled task.

Create Database Sequence (Data Management)—ArcGIS Pro | Documentation 

Delete Database Sequence (Data Management)—ArcGIS Pro | Documentation 

ListDatabaseSequences—ArcGIS Pro | Documentation (only available for file geodatabases: vote here to have it ported to enterprise geodatabases... https://community.esri.com/ideas/18798 )

That should just about do it....
0 Kudos
by Anonymous User
Not applicable

This is in ArcPro. I currently have script that runs this each night for the current day but recently it had a hiccup so I'm having to go back and correct a few months of sequence data. 

0 Kudos
JoeBorgione
MVP Emeritus

Are you looking for an automated solution to  correct a few months of sequence data?  I've done that sort of things with an update cursor:

fc = r'C:\some\path\to\your\data'
startValue = 1
fields = ['YourFieldName']
where = "A a sql select statement for a particular date'

arcpy.MakeFeatureLayer_management(fc,'fcLayer')

arcpy.SelectLayerByAttribute_management('fcLayer', 'NEW_SELECTION', where)

with arcpy.da.UpdateCursor('fcLayer',fields)as cursor:
    for row in cursor:
        row[0] = startValue
        cursor.updateRow(row)
        startValue += 1

If you have a list of dates, you could loop through it and create the where statement on the fly. I think the update cursor will update in order of object id for the selected set, but don't quote me on that.

***Untested for this particular application...

That should just about do it....