Can someone tell what is the reason behind this strange behavior? Thanks in advance.
well, without seeing your data it is a bit difficult to help.
A value might be null if
a) you don't have any data
b) this state is not part of the type you are selecting
What always is a good idea is to use IsEmpty() function to avoid such Null values, in your case IsEmpty(...,0).
Hope this helps