I would like to calculate a field (short integer) using other fields (short integer) present in the table. In some cases these fields may have null values for one or more of the fields. For example, the new field name is 'total' and total is based upon adding field1 + field2 + field3. Some records (rows) have values for field1, field2, and field3, but some rows only have values for field1 and field2, then field3 is null. Do I need to go and replace all null values with a numeric value? Or, is there some workaround within the VB or python script?
I'm using ArcMap 10.1
I've used a python example from below and have been unable to get it to work. Here is the code I'm using:
#calculate new field 'summed' in feature class 'test' inFeatures='test' fieldName01='summed' exSummed = "stack(!field01!+!field02!+!field03!)" codeBlock = "def stack(*args): return sum(filter(None, args))" arcpy.CalculateField_management(inFeatures, fieldName01, exSummed, "PYTHON", codeBlock)
where 'summed' is the field (short) I would like to populate and field01, field02, field03 are all short integers which may or may not have NULL's present.
I receive an error when I run this...
I'm sure it's something simple I'm doing wrong. Thanks-al