Wrong sum in calc element

verzevoul

Member
I have a calc element like


$a = (float)'{aaadiamerismata___posoenoikiasti_raw}';
$b = (float)'{aaadiamerismata___eispraxi_raw}';
$ratio = ($a - $b);
return round($ratio, 2);

and works fine.

But the sum of the rows is wrong. Is this a bug? Or I m doing something wrong?

Thanks!
 
What setting do you have in the calc element for 'Only Calc on Save' - if its set to no then the calculation value is not necessarily stored in the database and thus our sum code can't work out the correct value (as its run via an sql SUM() query on the recorded data.

So I would check that all db records contain a value for the calc element
 
ok !
The problem was with the _raw.
_raw wasn t necessery as I see. Beacause when I removed it, it seems to work now
 
Just to correct Rob ...

What setting do you have in the calc element for 'Only Calc on Save' - if its set to no then the calculation value is not necessarily stored in the database

The calc result is always stored in the database, on save.

"Calc on save ONLY" set to Yes means we will use that saved value when displaying the value, for instance when displaying Lists. This avoids the overhead of re-calculating the value for every row in the list.

Setting it to No means we will ignore the stored value, and re-calc it when displaying the value.

Which setting you use depends on the nature of your calc, and if it involves variables which are outside of the "scope" of the row it is on, i.e. you can't guarantee it should have the same result when displayed, as when the form was last saved.

For instance, if it involves looking up value(s) in other table(s), which may have been changed independently of "this" table / row, then you would need to set this to No, and re-calc the value every time it is displayed.

Whereas if the calc is something simple, like joining 'first_name' and 'last_name' into 'full_name', and you know the first and last name elements on that form will never be changed except by submitting the same form, you can set it to Yes, and only ever calc it when saving the form.

-- hugh
 
We are in need of some funding.
More details.

Thank you.

Members online

Back
Top