Calculate field questions

3610
3
03-18-2016 09:17 AM
BrettGonslaves
New Contributor

I have a field with street names, there are duplicate names in this collum. I want to add a number to the end of the name with a dash and have the multiple names count up incrementally (i.e MAIN ST-01, MAIN ST-02, MAIN ST-03, B ST-01)

there are several segments that have the same street name and would like to have a incremental number associated with it and then start back to -01 for a different street name.

what do i need to do in the field calculator to accomplish this?

0 Kudos
3 Replies
DarrenWiens2
MVP Honored Contributor

See this thread for how you can create a dictionary to work with incremental numbers by class, in the field calculator: https://community.esri.com/message/595324#comment-595324

In that case, the dictionary would look like {1:x, 2:y, 3:z, ...} ...where x,y,z are incrementing.

In your case, the dictionary would look like {'MAIN ST-':x, 'B ST-: y, ...} where x,y are incrementing.

BrettGonslaves
New Contributor

Being new to coding, what would the VB script or Pything script look like to accomplish this task?

0 Kudos
DarrenWiens2
MVP Honored Contributor

Codeblock (Python):

dict = {}
def myFunc(myClass):
  global dict
  dict[myClass] = dict.get(myClass, 0) + 1
  return myClass + "-" + str(dict[myClass])

Expression (change to your field name):

myFunc( !ST_NAME! )