# How to create a new value with information from multiple columns?

I have dataset that has columns that need to be sorted based on multiple columns.

The first column contains a name and the second a number, the names are not unique. What I want is a NewID from 1 to 10 per name based on the descending value of the number. Like this:

Any ideas how this can be done? Preferably in ArcMap.

• Do you need a python script or step by step algorithm as an answer? May 12, 2017 at 10:20
• Python script that can be used in field calculator would be nice. May 12, 2017 at 10:24
• ArcMap and FME require different solutions, which makes this question too broad. A Python solution requires you to provide the code you've developed to date. Please Edit the question. May 12, 2017 at 10:35
• I removed FME, I currently do not have a python script. May 12, 2017 at 11:23

I know you removed FME but for the record, a Sorter, sorting by the NameID and then secondly the number, followed by a Counter with the Counter ID set to the value of the NameID attribute will do exactly what you want.

``````import pprint
table = [
[1,'H',-1],
[2,'D',2],
[3,'D',8],
[4,'D',1],
[5,'H',68],
[6,'H',97],
[7,'H',88],
]

print 'Before sorting:'
print '[OBJECTID, NameID, Number]'
pprint.pprint(table)
print

print 'After sorting:'
print '[OBJECTID, NameID, Number]'
pprint.pprint(
sorted(table, key=lambda x: (x[1], x[2]))
)
``````

Excetuting this script gives:

``````Before sorting:
[OBJECTID, NameID, Number]
[[1, 'H', -1],
[2, 'D', 2],
[3, 'D', 8],
[4, 'D', 1],
[5, 'H', 68],
[6, 'H', 97],
[7, 'H', 88]]

After sorting:
[OBJECTID, NameID, Number]
[[4, 'D', 1],
[2, 'D', 2],
[3, 'D', 8],
[1, 'H', -1],
[5, 'H', 68],
[7, 'H', 88],
[6, 'H', 97]]
``````