ArcGIS Pro 3.3.1; file geodatabase
I want to use the field calculator to populate a new/blank field called ROW_NUM.
GROUP_ID VALUES ROW_NUM
1 0 2
1 1 1
1 0 3
2 0 1
2 0 2
3 1 1
3 0 3
3 1 2
It is my understanding that can’t currently be done using the Calculate Field tool (Python). Could that functionality be added?
If it were an Oracle SQL query, it would look like this:
select
GROUP_ID,
VALUES,
row_number() over (partition by GROUP_ID order by VALUES desc) as rn
from
MY_TABLE
@Bud What do you think about using this altered Sequential number?
Calculate Field (Data Management)—ArcGIS Pro | Documentation
# Calculates a sequential number
# More calculator examples at esriurl.com/CalculatorExamples
rec={}
def SequentialNumberByGroup(group):
global rec
pStart = 1
pInterval = 1
if group in rec:
rec[group] = rec[group] + pInterval
else:
rec[group] = pStart
return rec[group]
@JonathanNeal Thanks. At first glance, that script doesn't seem to order the sequential numbers by the VALUES field (descending), which is a requirement.
@Bud If sorting is a requirement, then the Sort tool will need to be ran first. Interesting idea though, to force processing order with the Calculate Field tool.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.