AnsweredAssumed Answered

Field Calc Sequential Number based on another column

Question asked by BRANDEN.HARDING on Oct 13, 2020
Latest reply on Oct 13, 2020 by BRANDEN.HARDING

I need to populate a column (Level4Code) with the field calculator that counts sequentially based on another column (Level3Name) and includes 4 digits. Here is an example of a table that's already populated correctly:

 

Level3NameLevel4Code
Adilabad

0001

Adilabad0002
Adilabad0003
Agar Malwa0001
Agar Malwa0002
Agra0001
Agra0002

 

The out of the box sequential code does not do it correctly since it doesn't loop based on any other column.

 

So far, I've tried this code snippet to count but I am not getting the results I need. This only seems to count the total number of times that word in Level3Name is present:

 

  1. dict = {} # make a dictionary  
  2. def myFunc(myClass): # this is the function  
  3.   global dict # specify global  
  4.   dict[myClass] = dict.get(myClass, 0) + 1 # if the dictionary key for the value exists, add 1 to it. If not, make it 0.  
  5.   return dict[myClass] # return the value for that key  

 

Any suggestions? I am new to Python so any help would be great.

Outcomes