Null values are disregarded by the avg function. So if a record doesn't have a value that record will not be included to calculate the average. That is correct imo, but it may not be what you want. In that case you can divide the sum by the count, i.e. sum(units)/count(units). Or you can try to replace the nulls in the script with real values.
However not sure that is the problem in this case: if you look at the screenshot (now attached) you should be able to see that for the current selection there is no null values! That's what is baffling me