Unable to extract the first six characters of a string using Calculate Field

3745
10
08-10-2021 10:35 AM
zhongying_gan
New Contributor III

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.

0 Kudos
10 Replies
jcarlson
MVP Esteemed Contributor

You could try using an Arcade expression, too, or SQL if that's applicable to the data source.

Left(GEOID, 6)
- Josh Carlson
Kendall County GIS
0 Kudos
zhongying_gan
New Contributor III

Hello. Thank you for your reply. I tried that but still got "<Null>".

0 Kudos
jcarlson
MVP Esteemed Contributor

Odd! You said that the field is definitely a string, but you could try to force it, just in case.

Left(Text(GEOID), 6)
- Josh Carlson
Kendall County GIS
0 Kudos
zhongying_gan
New Contributor III

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.

0 Kudos
JoeBorgione
MVP Emeritus

Are any of your original GEOID fields null or empty?

That should just about do it....
0 Kudos
zhongying_gan
New Contributor III

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.

0 Kudos
JoeBorgione
MVP Emeritus

Sometimes adding Python and ArcGis together makes for a good time!

That should just about do it....
0 Kudos
ZacharyUhlmann1
Occasional Contributor III

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.

0 Kudos
JoeBorgione
MVP Emeritus

@ZacharyUhlmann1 If you apply a field calculation with no records selected, the calculated value is applied to all records.

That should just about do it....
0 Kudos