I wanted to sum a column that has positive and negative values, and it just added the absolute values. The field is a decimal field, and I configured it to use "Total (Currency)".
For example, if the values are 300, 200, -50, it would summarize as 550 instead of 450.
I changed line 208 in file views_summarize.module from
$total += (float) preg_replace('/[^0-9\.]/', '', $val);
to
$total += (float) preg_replace('/[^-0-9\.]/', '', $val);
adding the "-" to the expression and that seemed to fix it.
I'm not a PHP expert, just at the hacking level and don't totally grok RegEx, so this might not be kosher but it works for me.
Comments
Comment #1
ErnestoJaboneta commentedThanks. That worked for me too. This should definitely be fixed.
Comment #2
peluhnya commentedIt does not work this way ((Is there another solution - very necessary.
Comment #3
oadaeh commentedThe attached patch fixes this problem. I added a \ before the minus so that it was treated literally, rather than as part of an expression.
Comment #4
peluhnya commentedThanks. works.
Comment #5
oadaeh commentedMarked #1830194: Negative figures count as positive when "Total" calculating as a duplicate of this.
Comment #6
oadaeh commentedThis has been committed to the 7.x-1.x branch, here: http://drupalcode.org/project/views_summarize.git/commit/74e5a7f