Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

I want to use the field calculator to get the sum of a couple of columns. The problem is that some of them has Null Values. I am not able to find a solution. I tried this Python functions:

stack( !basic.Blue_Thickness!, !basic.Green_Thickness!, !basic.Red_Thickness!, !basic.F1_Thickness! )

Version 1:

def stack(*args):
  myList = list(args)
  myList = [item for item in myList if (item is not None)]
  return sum(myList)

Version 2:

def stack(*args):
    return sum(filter(None, args))

Version 3:

def stack(*args):
  myList = list(args)    
  for item in myList:
    if item is None: 
  return sum(myList)

The result of all this functions is that I get always NULL back, only if there is a row with no NULL then I get a result.

Background: I have a File Geodatabase with one main table and some tables which joins this table. The calulation takes place only in the main table (source columns and write column). I am using ArcGIS 10.0. The Source of these functions is this discussion: calculating a field in which null values may be present

I would be really happy if somebody could help me.

cheers Immanuel

share|improve this question
Have you tried 'item == None'? –  PolyGeo Jun 30 '13 at 4:53
thank you unfortunately it didn't worked. i tried it two times: 'code' def stack(*args): myList = list(args) for item in myList: if item == None: myList.remove(item) return sum(myList) def stack(*args): myList = list(args) myList = [item for item in myList if (item != None)] return sum(myList)'code' –  user19605 Jun 30 '13 at 6:24
I'll try and run a more complete test. Perhaps you can edit your question to include the additional test(s) you ran and the errors that resulted from each test. –  PolyGeo Jun 30 '13 at 6:59
add comment

1 Answer

up vote 0 down vote accepted

I just ran the test below in the Field Calculator and it seemed to work.

def stack(item1,item2,item3):
  itemList = [item1,item2,item3]
  myList = [item for item in itemList if (item != None)]
  return sum(myList)

This was the Field Calculator settings I used:

enter image description here

and this is the test table with the result:

enter image description here

I think the only thing that I am not doing at the moment is joining through to another table but before I test that (I am using ArcGIS 10.1 SP1) perhaps you can confirm that this simple test is working for you. It's not as Pythonic but seems to work.

I'm not sure whether this is relevant but Python Central blogged on None just a day or so ago.

share|improve this answer
hey PolyGeo, many thanks for your help. I tried it many times and it didn't worked, even with your example. I am using ArcGIS 10.0 and today I had the chance to use the Computer of a friend, he has 10.1 and it work. So it has something to do with 10.0 or with my installation on my computer. Many thanks for your help. cheers Immanuel –  user19605 Jul 1 '13 at 2:25
add comment

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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