The aggregation settings (the emmajane episode!)

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:

  1. Turn on the aggregation setting (duh!)
  2. Make sure you don't have any sorting or filtering on data that is unique per database entry (such as sorting by post date)
  3. 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.
  4. 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 They rock.

By Johan Falk; Usage Attribution-Noncommercial-Share Alike 3.0