Problem: Field Calculator completes but values do not change
The Field Calculator is a great tool that can be used to modify field values all at once without taking the time for individual calculations. However, using the Field Calculator requires careful awareness of details such as field type, field length, and domains. In some situations, a user may see that the Field Calculator ran with no errors, but the field values have not changed.
The caveat to using Field Calculator is that the user must be aware of the types of fields being consumed.
If, for example, a user has a table with two columns and wants to fill out a third with text only if the first two match:
Using comparison code in Field Calculator:
This completes and appears to have succeeded in the Geoprocessing menu > Results, but the third column does not change.
This is because the two input fields, though in some cases may appear the same (1 in FieldName1 and 1 in FieldName 2), they are different field types:
Therefore, the string "1" is not equal to the short integer "1", and because there is no "else" statement to go with the "if" statement in the code block, nothing is returned to populate the field.
Solution or Workaround
Always check the field types for the inputs into the Field Calculator. Field types can be temporarily modified using code such as str(), int(), etc., to convert inputs to the same type for successful field calculation. In this example, an "else" statement can be added.
This then provides an output when the "if" statement is false, which could indicate that that further research is needed, specifically investigating the reason why the if statement is false, thus investigating the values and their types.