Views Aggregator Plus
A Views style plugin that performs post-query aggregation on Views results, offering aggregation functions not possible with native Views or database-level aggregation.
views_aggregator
Install
composer require 'drupal/views_aggregator:^2.1'
composer require 'drupal/views_aggregator:^2.0'
Overview
Views Aggregator Plus extends Drupal Views with powerful post-query aggregation capabilities. Unlike native Views aggregation which relies on database-level operations, this module operates on the result set after the database query has executed. This architectural difference enables aggregation functions that would otherwise be impossible.
The module provides a specialized table style plugin called "Table with aggregation options" that allows administrators to group and compress result rows based on identical values in one column while applying various aggregation functions to other columns. For example, you can group sales data by industry while summing turnover values and counting companies.
Key capabilities include enumeration of group members (listing all items in a group), tallying (creating textual histograms showing value counts), filtering rows using regular expressions, aggregating across entire columns with totals displayed in headers/footers/captions, and the ability to add custom aggregation functions. The module supports subtotals per group without compression, allowing display of original rows followed by calculated subtotals.
The module integrates well with Webform submissions, Commerce 2.x fields (including multiple currencies), and supports Twig syntax in "Global: Custom text" fields for mathematical operations and formatting.
Features
- Post-query aggregation that operates on rendered results rather than raw database values
- Group and compress functionality to collapse multiple rows sharing the same value into single aggregated rows
- Mathematical aggregation functions: COUNT, SUM, AVERAGE, MEDIAN, MINIMUM, MAXIMUM, RANGE
- String aggregation functions: Enumerate (list values with optional sorting and deduplication), Tally members (value counts in format 'Value (n)'), Display first member
- Filter rows using regular expressions to exclude non-matching results
- Column aggregation with totals displayed in table header, footer, or caption
- Subtotals mode that shows aggregated results after each group without compressing rows
- Case-insensitive grouping option for the Group and compress function
- Support for Webform submission data fields
- Support for Commerce 2.x price fields including multiple currencies in single columns
- Bootstrap theme integration with table styling options (bordered, condensed, hover, striped)
- Twig syntax support in Global: Custom text fields with number_format() filter preservation
- Click-sortable columns on aggregated results
- Custom aggregation function API via hook_views_aggregation_functions_info()
- Parameter support for functions (separators, regular expressions, precision values)
Use Cases
Sales Report by Industry
Group sales data by industry sector, showing total revenue (SUM), number of companies (COUNT), and average deal size (AVERAGE) per industry. Display column totals in the table footer showing overall figures.
Survey Results with Tallies
Analyze survey responses by grouping on question categories and using TALLY to show response distribution as 'Answer (count)' format, making it easy to see which options were most popular.
Inventory Report with Ranges
Group products by category and display price ranges (MIN - MAX) and quantity ranges per category, with overall ranges in the footer.
Customer Order History with Enumeration
Group orders by customer and enumerate all purchased products in a single cell, sorted alphabetically with duplicates removed, providing a quick overview of what each customer has bought.
Financial Report with Subtotals
Display detailed transaction rows grouped by account category, with subtotal rows after each category showing sums, while keeping the original detail rows visible. Final totals row shows overall figures.
Filtered Results by Pattern
Use the Filter rows function with a regular expression to exclude test data or internal entries from reports, showing only rows matching specific patterns like production order numbers.
Multi-Currency Commerce Report
Aggregate Commerce order totals where different orders use different currencies, with the module automatically calculating separate totals per currency and displaying them appropriately formatted.
Webform Submission Statistics
Analyze Webform submissions by grouping on a selection field and calculating statistics (count, average scores, etc.) on numeric submission data fields.
Tips
- Always assign 'Group and compress' to exactly one field when using other group aggregation functions (except Filter rows which works independently)
- Use the Parameter field to customize separators - default is '<br/>' for Enumerate and Tally, ' - ' for Range
- For case-insensitive grouping, enter 'case-insensitive' as the parameter for the Group and compress function
- Column aggregation can be used independently of group aggregation to add totals without grouping rows
- When using Global: Custom text with Twig syntax, place number_format() as the last filter to preserve formatting in aggregated results
- The Counter field (Global: Counter) is automatically excluded from click-sorting as its values are recalculated after sorting
- For Commerce price fields with multiple currencies, the module automatically calculates separate totals per currency
Technical Details
Hooks 2
hook_views_aggregation_functions_info
Define custom group and column aggregation functions. Each function is identified by its PHP function name and can provide both group-level aggregation (applied when grouping rows) and column-level aggregation (applied to create totals).
hook_views_aggregation_functions_info_alter
Alter existing aggregation function definitions. Use this to modify labels, disable functions, or change renderability settings of existing aggregation functions.
Troubleshooting 5
Try changing the field formatter to 'Plain text' instead of 'Default'. Some field types have formatters that don't work well with aggregated values.
Aggregated columns are click-sortable, but sorting happens on the aggregated values. For numeric columns, ensure the underlying data is numeric. The module compares values numerically when possible (so '$1,000' comes after '$9.99').
When you apply two aggregation functions to the same field, the second function operates on the results of the first, not the original data. Consider using separate fields if you need independent calculations.
Disable Views' native aggregation in the Advanced section (set 'Use aggregation: No'). Views Aggregator Plus is not designed to work alongside Views' built-in aggregation feature.
When 'Column aggregation row applies to entire result set' is selected with a pager enabled, the module must fetch all results to calculate accurate totals. For very large datasets, consider using 'applies to current page' or optimizing your View's filters.