DSum / Sum format

G

Guest

In Access query, I have two fields calculating running sum using DSum
function. In the third field I try to add the first two fields together. For
example,

field 1: DSum(...) = 123
field 2: DSum(...) = 123
field 3: [field 1] + [field 2] = 123123 (instead of 246)

Field 1 and field 2 are both general numbers. I don't know how to fix it.
Could anyone hlep me on this? Thanks.
 
A

Allen Browne

This is quite typical in JET. It doesn't understand whether the fields are
text (to be concatenated) or numeric (to be summed.)

The solution is to explicitly typecast. For example, if you are working with
Currency:
field1: CCur(Nz(DSum(...),0))
Use CLng() for whole numbers, or CDbl() for fractional numbers.

More info:
Calculated fields misinterpreted
at:
http://allenbrowne.com/ser-45.html
 
G

Guest

Thank you very much, Allen. This is very helpful.

Allen Browne said:
This is quite typical in JET. It doesn't understand whether the fields are
text (to be concatenated) or numeric (to be summed.)

The solution is to explicitly typecast. For example, if you are working with
Currency:
field1: CCur(Nz(DSum(...),0))
Use CLng() for whole numbers, or CDbl() for fractional numbers.

More info:
Calculated fields misinterpreted
at:
http://allenbrowne.com/ser-45.html

--
Allen Browne - Microsoft MVP. Perth, Western Australia

Reply to group, rather than allenbrowne at mvps dot org.

DavidC said:
In Access query, I have two fields calculating running sum using DSum
function. In the third field I try to add the first two fields together.
For
example,

field 1: DSum(...) = 123
field 2: DSum(...) = 123
field 3: [field 1] + [field 2] = 123123 (instead of 246)

Field 1 and field 2 are both general numbers. I don't know how to fix it.
Could anyone hlep me on this? Thanks.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top