ms access - Dsum Function in Query Field not working properly -
i have date based query returns 2 fields, week ending date , l2n, , want add third field provides rolling total of l2n field. have tried using dsum
follows:
runl2n: dsum("[l2n]","occupied apts & l2n", "week ending date=" & "'" & [week ending date] & "'")
in code above, l2n field want sum, , occupied apts & l2n query returns fields. query asks week ending date , delivers of records equal or proceed given week ending date.
it no worky right. goal runl2n field show rolling total of l2n field each record. in other words, if query returns multiple records, want show l2n field result, , show run2l2n field, sums l2n fields of records above , current record.
so if query returns 1 in l2n field, 3 next record, 5 next record , lastly 7 final record, want runl2n field show 1 first record, 4 next record, 9 next record , lastly 16 final record.
since field name includes spaces, bracket this: [week ending date]
assuming it's date/time type, use #
delimiters before , after date value.
finally think want sum rows [week ending date] <=
date in current row.
dsum("[l2n]","occupied apts & l2n", "[week ending date]<=" & format([week ending date], "\#yyyy-m-d\#"))
however if use correlated subquery, instead of dsum()
, compute running sum of l2n, won't have bother delimiters date value.
select y1.[week ending date], y1.l2n, ( select sum(y2.l2n) [occupied apts & l2n] y2 y2.[week ending date] <= y1.[week ending date] ) runl2n [occupied apts & l2n] y1;
Comments
Post a Comment