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
- can process Webform submissions
- 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.
Say the original View based on raw database results looks like below.
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.
|Food (2)||Heiny, McRonalds||$566,000,000|
|Clothing (1)||Cenneton||$ 99,000,000|
|IT (2)||AcquiB, PreviousBest||$ 30,000,000|
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".
A live example using lots of columns and rows, as well as exposed filters: Vizala, see this blog post. Three other real-life applications with screenshots are in this article: "But that's easy in Drupal isn't it?"
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 the included submodule,
views_aggregator_more_functions.module and follow the same pattern.
Works great with:
- Webform 7.x-4.x: aggregate your webform submission results tables
- Drupal Commerce, see bottom screenshot. Group and compress was applied to the Order Status field. # Orders was counted and the Totals field Summed, while a textual histogram with counts (Tally) was executed on the User name. Column aggregations were added also for #Orders and Totals, displayed in the bottom row.
- Table Trash, responsive table options as well as buttons to export to CSV, PDF
- HighchartTable: add charts to your aggregated tables with a single click
- Views Field View, see
- Maintenance status: Actively maintained
- Development status: Under active development
- Module categories: Content, Views
- Reported installs: 7,415 sites currently report using this module. View usage statistics.
- Downloads: 32,364
- Automated tests: Enabled
- Last modified: 4 December 2015
- Stable releases for this project are covered by the security advisory policy.
Look for the shield icon below.