Aggregation involves the compression of result rows
Screenshot of available aggregation functions

As the Views and Views Calc modules rely on the database to perform aggregation, you only have limited options at your disposal.
As the great Merlin himself said: "You can't aggregate a PHP expression in the database.  :/ ".
That's where Views Aggregator Plus comes in. In addition to what Views and Views Calc do, this module:

  • enumerates group members
  • produces tallies, i.e. textual histograms
  • aggregates on Views PHP code-snippet evalutations
  • can filter out result rows on regexp patterns
  • gives you sorting on Views' Math expressions
  • lets you add your own custom aggregation functions

... and it puts summary statistics at the bottom of your aggregated table as well!

Recap: what is aggregation again?

In the context of Views tables and this module, aggregation is the process of grouping and compressing result rows on the identical values of one column, while at the same time applying "summary" (aggregation) functions on other columns. For example, you can group the result set on a taxonomy term, so that all rows sharing the same value of the taxonomy column are represented as single rows, with aggregation functions like COUNT, ENUMERATE or SUM applied to the remaining columns.

Example

Say the original View based on raw database results looks like below.

Industry Company Name Turnover
IT AquiB $  25,000,000
Clothing Cenneton $  99,000,000
Food Heiny $  66,000,000
IT PreviousBest $    5,000,000
Food McRonalds $500,000,000

Then with the grouping taking place on, say Industry, and aggregation functions TALLY, ENUMERATE and SUM applied on Industry, Company Name and Turnover respectively, the final result with a descending sort on the last column will display like below. Note that the module identified three groups. It also added a totals row, Views Calc style.

Industry Companies Turnover
Food (2) Heiny, McRonalds $566,000,000
Clothing (1) Cenneton $  99,000,000
IT (2) AcquiB, PreviousBest $  30,000,000
Totals             5 $695,000,000

But that's just the beginning. Remember, you can aggregate on Views PHP expressions, so the possibilities are endless! See the README for examples using PHP code snippets.

For the "totals" row you may use the module's Math expression column aggregation function and replacement tokens to calculate a field as, say, the product of two preceding fields.

How to use

On the main Views UI page, admin/structure/views/view/YOUR-VIEW/edit/page,
under Format, click and instead of Table, click Table with aggregation options. Having arrived at the Settings page, follow the hints under the header "Style Options".

More examples

Three real-life applications with screenshots are in this article: "But that's easy in Drupal isn't it?"

FAQ's

Q: With Views Aggregator Plus installed, is there a reason to use the Views or Views Calc aggregation options?
A: Views Aggregator Plus has all the standard aggregation functions of Views and Views Calc (COUNT, SUM, AVERAGE, MIN, MAX), plus more. For huge datasets the native db functions employed by Views and Views Calc are possibly a little faster in execution than Views Aggregator Plus's post-query approach, but I have to see evidence that it's noticeable.

Q: As a developer can I add more aggregation functions in a maintainable fashion?
A: You can write your own mini-module for this in which you implement hook_views_aggregation_functions_info(). It's easy. See how it was done for this module, file views_aggregator_functions.inc and follow the same pattern.

Works great with:

Project Information

Downloads