Force Views Aggregator Plus to display Zero on SUM

I’ve used the Views Aggregator Plus module on several projects and I love it! It has a lot of great options and can be extended with a little custom programming to include your own column functions.

 

One minor issue is that when using the SUM function, totals with a zero amount show up blank. There is an open issue with a proposed solution, but in case you need a solution today (and don’t mind some programming) here’s what you can do.

 

Using the hook_preprocess_views_aggregator_results_table() function, you can check for empty values and alter the results to show zero.

 

Below is an example.

/**
 * Implements hook_preprocess_views_aggregator_results_table().
 */
function example_preprocess_views_aggregator_results_table(&$variables) {
  $view = $variables['view'];
 
  if ($view->name === 'my-view-name') {
    foreach ($variables['totals'] as $column_name => $value) {
      if (empty($value)) {
        $variables['totals'][$column_name] = 0;
      }
    }
  }
}

 

If your view uses other column functions besides SUM, you'll want to filter your search to only include those columns.
Hope this helps!