Sign up ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

This question already has an answer here:

Is there a way to auto populate a sequence of numbers based on another attribute in a table? For example, if field "Name" has a sequence of numbers from 1 to 10, and I want to number all the rows in the table that associated to "Name = 1" from 1 to 10, and then start this process over when "Name = 2" etc (see attached graphic). Can this be done within the Field Calculator, with a plugin, or does it need to be coded?

Thanks...enter image description here

share|improve this question

marked as duplicate by Devdatta Tengshe, whuber Feb 19 '13 at 6:44

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

1 Answer 1

I was able to get some help from someone here, and thought I would share the results:

counter = 0
p_name = ""

def count_values(name):
  global counter
  global p_name

if p_name == "":
  counter += 1
elif p_name == name:
  counter += 1
elif p_name != name:
  counter = 1

p_name = name

return counter
share|improve this answer

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