I'm trying to calculate a total demand in ArcGIS 10.2.2, stored in fields Demand1, Demand2, ... , Demand20. Some of them contain a numeric value. The others have a <Null> value. The sum therefore always returns <Null>.

I've tried in Python to define, in the pre-script a function:

def D(a):
   0 if a else 1

(as recommended in Field calculator if and elseif statement with <Null> values in ArcGis 10.1, with correct indents, etc.)

then in the code

 D( !Demand1! ) + D( !Demand2! ) + ... + D( !Demand3! )

It cannot compute. Do you have any suggestions?


1 Answer 1


If you're defining a function, you need to use a return statement within it for D() to actually return a value. Use return 0 if a else 1.

  • Thanks for your help! The return saved everything, but was more likely 'return a is a else 0' and that way it works. Commented Feb 18, 2016 at 9:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.