I am using arcmap 10.1 and working in a personal geodatabase. I am trying to add a sequential number to an [encounterID] field to populate a [sightingID] field. What code would i use?

For example I want to sequentially number my encounter ID's and populate the sighting id field as it appear in the sighting ID below and for multiple records.

Column 1


Column 2

  • Welcome to GIS SE! As a new user please take the tour to learn about our focused Q&A format. – Midavalo Mar 27 '17 at 20:41

In the field calculator window, select Python Parser, check the Show Codeblock box.

Pre-logic script code:

from collections import defaultdict
valueUsage = defaultdict(int)
def unique_id(inputfield):
    valueUsage[inputfield] += 1
    new_value = "{0}_{1}".format(inputfield, valueUsage[inputfield])
    return new_value


unique_id( !encounterID!)

enter image description here

The result in the attribute table

enter image description here

It doesn't matter the order in the table, it will number them sequentially based on the value in the encounterID field.

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.