Anyone who has been using Drupal more than just a little bit knows that Views is one of the most important tools you got in the Drupal tool box. Personally I'm convinced that Drupal wouldn't be where it is if it wasn't for Views. It just rocks.
With the 3.x branch, a number of new awesome features were added to Views – most notably the pluggable query backend, but also things like plugins for headers and footers, and/or groupings for filters and the ability to turn off node access query rewrites. But one of the additions did always escape my attempts to understand it: use aggregation. No matter how I tried to tweak the Views settings, it just didn't make sense to me.
Until a few days ago, that is. Now I know, thanks to patience from Island Usurper and emmajane. I am celebrating this by releasing three screencasts introducing aggregation, showing how to make use of aggregation and relationships, and using aggregation with other handlers or multiple-value fields.
If you don't want to watch screencasts, here's short-short version (spoiler alert!):
- Aggregation makes Views not return items from the database, but groups of items.
- You find the aggregation setting in the advanced section in Views.
- Add any fields you want to use for grouping, in aggregation mode "group similar results".
- Add any fields you want to do calculations on – sums, averages, counts, etc. (Set the appropriate aggregation mode.)
- Make sure you don't, for example, have sorting on publish date – it will make your aggregation more or less meaningless. (Views adds this by default, which was the thing stopping my attempts to understand aggregation.)
PS 1: Adding these screencasts to the old Taming the Beast screencast series, I also add a "Cred to the Views maintainers" link. If you feel that Views is a good thing, it can't hurt to let the maintainers know.
PS 2: Don't miss the Rules Mastery training at DrupalCon Denver. It will rock.

Comments
moniuch
December 25, 2011This may save someone hours of investigation: currently there seems to be conflict between Devel modules and aggregation, in that aggregation does not work (the grouping field gets repeated) when you have Devel enabled. At least that's what's happening on my install.
Johan Falk
December 26, 2011 Double check that you don't have sorting on published date. That's what happened to me, and made me not understand aggregation for quite some time.moniuch
December 26, 2011Just double-checked it: no date involved in there. I understand aggregation, I just did not understand that it worked when I logged out. This lead me to investigating the stuff that was available to admin and the Devel module turned out to be the black sheep.
Johan Falk
December 27, 2011 Huh, interesting. Maybe it is some kind of trace that Devel + Views in combination puts on database queries, that makes each row unique. I think I had Devel enabled when recording these screencasts, but there may of course be many things involved in strange bugs.moniuch
December 27, 2011You know, I'm a good tester :) Murphy's cousin... if there's a hidden quirk, I'll see it
Johan Falk
December 28, 2011 Heh, then you'll have a lot of oppurtunities to make Drupal coders happy! If you also make automated tests for the stuff you find, you'll go to 10 on Certified to Rock in no time. :-) (If you, like me, find SimpleTest a bit too much at the moment I recommend checking out Selenium. Incidentally, there is a short screencast series about that awesome tool here at dev.nodeone.se.)moniuch
January 2, 2012If you care for a confirmation of the Devel quirk, please visit this page http://drupal.org/node/388140 and find the Caution section :)
BTW, a screencast on customizing table output of a view would be awesome, I'm having a hard time configuring the header.