Hello I'm using arcgis pro. I opened up a feature layer in a geodatabase, and I would like to extract the first six characters of the GEOID (string2.png). I have checked that the field type of GEOID is text. I created a new field called "GEOID_5", and I made it a text field too. Then I right-clicked the field, then clicked "Calculate Field", and then put in the following formula (string.png). I'm sure the formula is correct because I borrowed it from a similar case in https://desktop.arcgis.com/en/arcmap/latest/manage-data/tables/calculate-field-examples.htm. However, after the calculation, all the entries in GEOID_5 is <Null>. I was wondering whether anyone would offer me some thoughts. Thank you.
You could try using an Arcade expression, too, or SQL if that's applicable to the data source.
Left(GEOID, 6)
Hello. Thank you for your reply. I tried that but still got "<Null>".
Odd! You said that the field is definitely a string, but you could try to force it, just in case.
Left(Text(GEOID), 6)
Thank you for your reply. I just tried to use my python formula again and it suddenly worked. I don't know why this morning it didn't work for several times but suddenly worked in the afternoon. I didn't change a thing.
Are any of your original GEOID fields null or empty?
Hello. Thank you for your reply. None of the GEOID fields are null or empty. I just tried to use my python formula again and it suddenly worked. I don't know why this morning it didn't work for several times but suddenly worked in the afternoon. I didn't change a thing.
Sometimes adding Python and ArcGis together makes for a good time!
It may be you didn't have the rows selected. Calculate Field will only apply to selected rows HOWEVER - I am not sure what happens when NO rows are selected. My instinct (and memory sort of) tell me that nothing is affected or changed when Calculate Field is applied with no rows selected.
@ZacharyUhlmann1 If you apply a field calculation with no records selected, the calculated value is applied to all records.