You can’t use calculated fields for this, since a calculated field only acts on a single document at a time. To accomplish what you’re after, you’ll need to use the query bar to pre-group the data (i.e. to count it), after which you can apply further transformations. Here’s one way to do it: