Problem/Motivation

When using the regular "group_by" (views aggregation) option to calculate a sum (say of a numeric field), the views aggregator plus column sum function returns the sum of the first n (depending on the views result count) entity fields instead of the sum of the aggregated sums.

Steps to reproduce

Create a view of entities with a numeric field and a second field for grouping (in my case a taxonomy), set views aggregation (not the table aggregation!) to calculate the sum of the numeric field grouped by the other field. Set views aggregator plus table and set column operation to sum. Behold the wrong sum.

Proposed resolution

In getCellRaw, try to access $result_row values directly before doing additional steps.

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

attisan created an issue. See original summary.

attisan’s picture

Assigned: Unassigned » attisan
Status: Active » Needs review
StatusFileSize
new1.48 KB
jordik’s picture

Status: Needs review » Postponed (maintainer needs more info)

Is there a particular reason for you to use the Views Aggregator Plus in combination with the native views aggregation?
All the functionality you describe is covered by Views Aggregator Plus - just use Group Aggregation.
On the column you want to group by set Group and compress on the other columns use Sum. Use Sum in Column Aggregation for the total sums.

rex.barkdoll’s picture

Version: 8.x-1.x-dev » 2.0.1

I'm not the OP, but here's my example:

I'm working with Drupal Commerce's Daily Sales Report View.

  • By default, it uses Views Aggregation to show the date and how many orders were placed on that date. Using the Count function on the Order ID field.
  • But I want to do better and have a total at the bottom of the page showing how many orders were made for that time period.
  • So now, I disable Views Aggregation and switch the format to Table with Aggregation options.
  • After some clicking around, I figure out that I have to set my Date Column to Group Aggregation: Group and Compress and my Order ID column to Group Aggregation: Count. Success, I was able to recreate the original view. But there's still no total.
  • Now, in the Order ID column, I Apply Column Function: Sum and the total it returns is not the counted numbers combined. Instead it's all the Order ID's added together. (So what should be a total of 17 is 1346).

In my brain, when I started all of this, (and this is how my comment here relates to the original post) I just wanted to keep the original settings from Views Aggregation and then turn on the column Sum function and have it show me the total number of orders placed. If I couldn't do that, I felt like I figured out how to recreate the table using all of Views Aggregator Plus' functions, but it still failed to give me the result I want.

For the developers, I think part of the problem you're fighting is that something that feels like it should be intuitive wasn't. This might be solved with examples and documentation.

The other part is that, in my case, the patch above hasn't solved my problem and I'm not sure how else to get this calculation to run correctly.

Just to be succinct: My issue is that I have a column that is using the count function to get a total number of sales for the day based on how many order IDs there are, but the column's sum function isn't using the result of the count that's visually displayed, it's just adding all the ID's together, resulting in a number totally different than what the count function is returning.

Let me know if I need to put my problem in a new issue. Happy to do that.

jordik’s picture

If you use count in the column aggregation it should give you the correct number (17).

marioki’s picture

I second the need for this feature, because it greatly improves performance if grouping is done by the database. Patch #2 works well, is there any reason not to include this in the module, at least as a configurable option so existing views do not break?

tvoesenek’s picture

Version: 2.0.1 » 2.1.x-dev
StatusFileSize
new1.44 KB

This is a reroll of patch #2 against 2.1.x

tr’s picture