You could calculate the number you have to divide with: create a variable, and check per month (object?) if it has any data. you could use retrieves or filters for this. If there is data, add 1 to the variable. This way, if only six months have data for instance, the variable value will be six and you'll divide by six.
There are more checks you can add (to exclude situations like having data one month, but none the next) but it's up to you how complex/extensive this should be.