This screencast shows how to use the "aggregation" setting, lurking in the advanced options in Views. The aggregation setting makes Views return not one row per item in the database, but one row per aggregation group. Perhaps more importantly, it also makes it possible to count the number of items baked into each row, or sum them up, or calculate their average, or count the number of unique items, or…
To use aggregation in a sensible way:
- Turn on the aggregation setting (duh!)
- Make sure you don't have any sorting or filtering on data that is unique per database entry (such as sorting by post date)
- Add the fields you want to display as unique groups – such as content type (if that's a relevant category), author, shirt size, etc. Use the 'group similar results together' aggregation mode.
- Add the fields you want to do calculations on – sums, averages, counts, etc. Set the appropriate aggregation mode.
Note 1: the aggregation settings will appear for all handlers – not just the field settings. At least for relationships, though, the aggregation doesn't seem to do anything (which for a database perspective makes sense).
Note 2: If Views doesn't return the things you expect it to, it might be a good idea to turn on the display of SQL query. That's done in the Views settings (admin/structure/views/settings).
Feel free to praise Island Usurper and emmajane on IRC or drupal.org. They rock.