Introduce count_by with a secondary field