What are you trying to achieve (COUNT)?
Are you taking simple counts or Running Counts (RCOUNT)?
Both are very different. Please check
Your issue is probably one of the order of aggregation, due to whether your objects are physical or logical, on the case of case statements and aggregation you nearly always need it to be based on physical measures.
My advice would be to create your logic in the rpd if possible, reproduce your case statement based on the physical, then your results will not be spurious.