Full Version: DSUM confusion
UtterAccess Discussion Forums > Microsoft® Access > Access Queries
smithochris
I have a query with the following fields:

Month, Year, YearMonth, AmtW, AmtD, TotD, TotW

The YearMonth field just concatenates year, and then month. The TotD and TotW fields are DSUMS, but I can't get them to work properly. I want the DSUMS to sum all values in AmtW or AmtD where YearMonth is less than or equal to what the current row is. For example:

Month..........Year............YearMonth.........AmtW.........AmtD..........TotD
............TotW
April...........2005.............200504.............($5)...........$20..........
...$20.............($5)
June..........2005.............200506.............$0..............$100..........
$120............($5)
Sept...........2006............200609.............($45)...........$0............
.$120............($50)

I am trying to use the YearMonth for the condition in DSUM, but I can't get it to work right. Any ideas? Thanks.
schroep
TotW: DSUM("AmtW","tableorqueryname","YearMonth<'" & [YearMonth] & "'")

Note that YEARMONTH needs to be a field or concatenated expression in the underlying table or query.
smithochris
That works great. Thanks!
schroep
Glad to help. If you want to do less than or equal to, we should change that to:

TotW: DSUM("AmtW","tableorqueryname","YearMonth<='" & [YearMonth] & "'")
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.