I've tried your formula as described, and it's not giving the results I anticipate. For instance, your formula basically says
I'm interested only in the last 3 months, so going by today's numbers month 9 would satisfy the requirement of current month - C month being less than 3 (5-9=-4), but it's not one of the last 3 months.
Going to "if in a 3 month period there's 1 month where there's no spend, then the average will be divided by 2", whether there's 1, 2 or 3 months with expenses in the last 3 months, we'd always divide by 3. If expense is 30 in month 1, 0 in month 2, and 0 in month 3, the average would be 10.