# Calculate feature ranks within ESRI table

I have a line feature class of streets that has been intersected with overlapping polygon "selection areas".

For each selection area, I aim to calculate the rank (1-n) for the streets from longest to shortest within the selection area as I have done for the selected records in the image below.

I had naively suggested that it would be a quick "summarize" operation, but now that I'm actually working on it, there is no built-in function as far as I can tell.

I have tried to manually iterate through summarizing "selection area" for the maximum length value, but this is prohibitively long at best. And at worst, I miss a step along along the way and have to start over.

Can you suggest a field calculator function that will calculate the length rank of each street for each selection area?

UPDATE: I can do this in excel as follows, so I can move forward in my task. But I do still want to know if/how I can do this in the field calculator interface or ArcMap in general

``````=1+SUMPRODUCT((\$B\$2:\$B\$13469=B40)*(\$C\$2:\$C\$13469>C40))
``````

• Sort descending and use gis.stackexchange.com/questions/200150/… Sep 4, 2018 at 19:53
• This appears to calculate 1-n for all records in my group (Selection area) by the order of the ascending order of "ObjectID" not the descending street lengths for each group. I believe the processing order is based on object ID regardless of table sorting. Using your code, I do get 1-n but they are not ranked by length. For example, what should be #2 in the selected group above returns as #6. Sep 4, 2018 at 20:12
• Sort your table in descending order using length. Unselect all and proceed with selection area as group. You didn't read 1st line in my comment. Sep 4, 2018 at 20:40
• No dice. Regardless of sorting, it auto-increments within each given group in order of the ObjectID - not the length Sep 4, 2018 at 20:44
• I mean sort to a new table, using tool called Sort. Sep 4, 2018 at 20:46

To summarize the conversation with FelixIP in the above comments:

This question provides an auto increment function within groups defined by another field for field calculator:

Auto incrementing field based on groups within feature class?

``````d={}
def GroupOrder(groupID):
N=d.get(groupID,0);N+=1
d[groupID]=N
return N
``````

However, this is limited in that it auto increments within each group in order of ObjectID. The work around was to use Sort to produce a new FC where records (ObjectIDs) were reordered by the length value I was looking to rank. As a result, auto-increment on this sorted table worked perfectly since, for each group, all records were already sorted correctly relative to each other in the table (though they were likely separated by records from other groups in between). So as the function moved down the table and encountered a new group member, it was guaranteed to be a shorter length (+1 rank) than the previous group member.