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

ErnestoJaboneta’s picture

Thanks. That worked for me too. This should definitely be fixed.

peluhnya’s picture

Priority: Normal » Critical

It does not work this way ((Is there another solution - very necessary.

oadaeh’s picture

Version: 7.x-1.0 » 7.x-1.x-dev
Assigned: Unassigned » oadaeh
Priority: Critical » Normal
Status: Active » Needs review
StatusFileSize
new523 bytes

The attached patch fixes this problem. I added a \ before the minus so that it was treated literally, rather than as part of an expression.

peluhnya’s picture

Thanks. works.

oadaeh’s picture

oadaeh’s picture

Status: Needs review » Fixed

This has been committed to the 7.x-1.x branch, here: http://drupalcode.org/project/views_summarize.git/commit/74e5a7f

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.