DSum with dates help

Raysoc

Board Regular
Joined
Feb 10, 2009
Messages
227
Need a running sum on weeks, but all I have is a single date column, so what I did was this:

column 1: Week: Format([Date],"yyyy - mm - ww")

column 2: $Amt

column 3: WTD: DSum("$Amt","MyTable",Format([Date],"yyyy - mm - ww") & " <= " & [Week] & "")

and tried this: WTD: DSum("Adj Amt","OneBill",Format([Date],"ww")<=[Week])

This does not work, the example I was following was from an example where there was a month field in the table using numbers to represent the week, i.e. 1,2,3,4 so it made sense, im trying to evaluate two formatted dates and have it total them up.. what am I doing wrong here?

Thanks!


on a side note... does anyone know how to make it pick actual weeks, i.e. Dec27-Jan02 is a week, but in access using the format above for ww 27-31 is a week 54 and 1-2 is week 1, im worried that at the end of the month 31 will be a single week and feb 1-6 will be a week instead of 31-6.

I like that it does this but want to know how to switch between, weeks in a month and weeks in a year.

Thanks!
 
Last edited:

Excel Facts

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.
There is no good way to do running sums in a query/table. you could use a linked Excel file to do your calculations.
 
Upvote 0
Try adding single quotes to your dsum function.

DSum("$Amt","MyTable",Format([Date],"yyyy - mm - ww") & " <= '" & [Week] & "'")
 
Upvote 0
Week: Format([Date],"yyyy - mm - ww") Group By
Adj Amt Sum
WTD: DSum("Adj Amt",Format([Date],"yyyy - mm - ww") & "<=" & [Week] & "'") Expression

Gives this result:

******
<table bgcolor="#ffffff" border="1" cellspacing="0"><caption>Sum Adj by week</caption> <thead> <tr> <th bordercolor="#000000" bgcolor="#c0c0c0">Week</th> <th bordercolor="#000000" bgcolor="#c0c0c0">SumOfAdj Amt</th> <th bordercolor="#000000" bgcolor="#c0c0c0">WTD</th> </tr> </thead> <tbody> <tr valign="TOP"> <td bordercolor="#c0c0c0">2009 - 12 - 53</td> <td bordercolor="#c0c0c0" align="RIGHT">-$212,837.50</td> <td bordercolor="#c0c0c0">#Error</td> </tr> <tr valign="TOP"> <td bordercolor="#c0c0c0">2010 - 01 - 1</td> <td bordercolor="#c0c0c0" align="RIGHT">-$94,846.54</td> <td bordercolor="#c0c0c0">#Error</td> </tr> <tr valign="TOP"> <td bordercolor="#c0c0c0">2010 - 01 - 2</td> <td bordercolor="#c0c0c0" align="RIGHT">-$5,847,897.37</td> <td bordercolor="#c0c0c0">#Error</td> </tr> <tr valign="TOP"> <td bordercolor="#c0c0c0">2010 - 01 - 3</td> <td bordercolor="#c0c0c0" align="RIGHT">-$2,949,875.62</td> <td bordercolor="#c0c0c0">#Error</td> </tr> <tr valign="TOP"> <td bordercolor="#c0c0c0">2010 - 01 - 4</td> <td bordercolor="#c0c0c0" align="RIGHT">-$8,938,763.82</td> <td bordercolor="#c0c0c0">#Error</td> </tr> <tr valign="TOP"> <td bordercolor="#c0c0c0">2010 - 01 - 5</td> <td bordercolor="#c0c0c0" align="RIGHT">-$3,458,969.07</td> <td bordercolor="#c0c0c0">#Error</td> </tr> <tr valign="TOP"> <td bordercolor="#c0c0c0">2010 - 01 - 6</td> <td bordercolor="#c0c0c0" align="RIGHT">-$4,164.92</td> <td bordercolor="#c0c0c0">#Error</td> </tr> </tbody> <tfoot></tfoot> </table>
Which I dont understand...
 
Upvote 0
I think your missing the table name reference as the second parameter.

DSum("Adj Amt","TableName",Format([Date],"yyyy - mm - ww") & "<=" & [Week] & "'")
 
Upvote 0
Thanks for the suggestion Murf but that doesnt seem to have changed anything just shows #error
 
Upvote 0

Forum statistics

Threads
1,214,646
Messages
6,120,717
Members
448,985
Latest member
chocbudda

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top