1

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 Answers1

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.

nmpeterson
  • 8,276
  • 33
  • 59