There is a glitch when you enter a formula using a categorized variable and you select aggregate. The system seems to think it needs to immediately add the extra rows for the categories, not realizing that aggregation eliminates the need to do that. Also, it loses the designation for aggregation in the process so you end up with a variable with all the category rows and a formula that no longer is flagged as aggregated. When you then go back in and select aggregation, the system retracts all the item rows and ends up working correctly.
Thanks for reporting @wivers !