Select to view content in your preferred language

field calculator help

627
3
05-25-2023 03:27 AM
Labels (3)
JoãoToscano
Emerging Contributor
Hello community, I need help working with the attribute table, I need to number all the lines in my case from 1 to 357, but one of the columns with the name of the properties has to be in alphabetical order, how can I do this using the field calculator. 
Thanks in advance for your attention

 

0 Kudos
3 Replies
JohannesLindner
MVP Frequent Contributor

Switch language to Arcade, use this expression (change "TextField1" to the name of your field):

var oid = $feature.OBJECTID
var txt = $feature.TextField1

var previous = Filter($featureset, "TextField1 < @txt")
var same_lower = Filter($featureset, "TextField1 = @txt AND OBJECTID < @oid")
return Count(previous) + Count(same_lower) + 1

Have a great day!
Johannes
0 Kudos
JoãoToscano
Emerging Contributor
Thanks for the quick reply, I'm relatively new to working with Arqgis, how do I change the Field Calculator language to arcade?

 

0 Kudos
JohannesLindner
MVP Frequent Contributor

JohannesLindner_0-1685027615197.png

But this is for ArcGIS Pro, and I didn't realize that you posted this question in the ArcMap group.

 

If you're working with ArcMap, it's much easier to do this task with a little Python script.

 

Open your Python Window

JohannesLindner_1-1685028433615.png

 

 

Paste in this script, edit the first three lines and execute (hit Enter).

table = "TestPolygons"  # the table path or layer name
text_field = "TextField1"  # the sort field
number_field = "IntegerField1"  # the field that will be calculated

i = 1
with arcpy.da.UpdateCursor(table, [text_field, number_field], sql_clause=[None, "ORDER BY {}".format(text_field)]) as cursor:
    for row in cursor:
        row[1] = i
        cursor.updateRow(row)
        i += 1

 


Have a great day!
Johannes