function hook_aggregation_info() { $new_aggregation_methods = array( 'group_concat' => array( 'title' => t('Group Concat'), 'method' => 'views_query_default_aggregation_method_simple', /* This uses the default aggregate callback, which simply uppercases the array index for this function and wraps it around the field with parenthesis*/ 'handler' => array( 'argument' => 'views_handler_argument_group_by_numeric', 'filter' => 'views_handler_filter_group_by_numeric', 'sort' => 'views_handler_sort_group_by_numeric', ), ), 'sum_positive' => array( 'title' => t('Sum Positive Values'), 'method' => 'views_query_sum_polar_aggregation', // Custom function below. 'handler' => array( 'argument' => 'views_handler_argument_group_by_numeric', 'filter' => 'views_handler_filter_group_by_numeric', 'sort' => 'views_handler_sort_group_by_numeric', ), ), 'sum_negative' => array( 'title' => t('Sum Negative Values'), 'method' => 'views_query_sum_polar_aggregation', // Custom function below. 'handler' => array( 'argument' => 'views_handler_argument_group_by_numeric', 'filter' => 'views_handler_filter_group_by_numeric', 'sort' => 'views_handler_sort_group_by_numeric', ), ), 'coalesce' => array( 'title' => t('Coalesce'), 'method' => 'views_query_default_aggregation_method_simple', 'handler' => array( 'argument' => 'views_handler_argument_group_by_numeric', 'filter' => 'views_handler_filter_group_by_numeric', 'sort' => 'views_handler_sort_group_by_numeric', ), ), ); return $new_aggregation_methods; } function views_query_sum_polar_aggregation($group_type, $field) { $condition = ($group_type == 'sum_positive') ? '>' : '<'; return 'SUM(IF(' . $field . $condition . '0, ' . $field . ', 0))'; }