COUNT(amount) counts only non-NULL amount values inside each category group.
highlighted = computed this step
Input table
Start with sales rows where one pen amount is NULL.
Group query
Group by category and count only non-NULL amount cells.
GROUP BY category, COUNT(amount)
Grouped output
The pen group has three rows, but only two non-NULL amounts.
non-NULL amount counts