DSum and date as criteria

Hello all,

I am calculating a running sum within a query using the DSum function.

DSum("[sngAmount]";"[tblAccountMovements]";"STR(CDBL([datDate]))<=" &
Str(CDBL([datDate])))

sngAmount contains positve or negative numbers from the table
"tblAccountMovements".
"datDate" is a date field from the same table.

I would like to calculate a running total within a query that is
sorted by "datDate". Basically, the above formula works fine. However,
there arise problems if datDate contains a date several times. If this
is the case, the calculation in the query gives me the total for the
whole day in every record with the specific date.

Here's an example:

tblAccountMovements

datDate          sngAmount
01.01.09          1000
15.02.09          -200
30.06.09          5000
30.06.09          -2000

The result looks like this:

datDate          sngAmount          Running total
01.01.09          1000                   1000
15.02.09          -200                     800
30.06.09          5000                   3800 (this should be 5800)
30.06.09          -2000                  3800

The third row should give me a value of 5800, the rest is fine.
Instead, the third row is already the sum of the two numbers for the
30.06.09 (5000-2000=3000).

How am I supposed to adjust the formula to incorporate different
values for the same date?

Regards,
Andreas
0
Andreas
12/29/2009 7:29:19 PM
access 16762 articles. 3 followers. Follow

4 Replies
1517 Views

Similar Articles

[PageSpeed] 55

Keeping in mind that records are like marbles in a box (no particular order) 
how would you determine which movement occured first on June 30?

-- 
Duane Hookom
Microsoft Access MVP


"Andreas" wrote:

> Hello all,
> 
> I am calculating a running sum within a query using the DSum function.
> 
> DSum("[sngAmount]";"[tblAccountMovements]";"STR(CDBL([datDate]))<=" &
> Str(CDBL([datDate])))
> 
> sngAmount contains positve or negative numbers from the table
> "tblAccountMovements".
> "datDate" is a date field from the same table.
> 
> I would like to calculate a running total within a query that is
> sorted by "datDate". Basically, the above formula works fine. However,
> there arise problems if datDate contains a date several times. If this
> is the case, the calculation in the query gives me the total for the
> whole day in every record with the specific date.
> 
> Here's an example:
> 
> tblAccountMovements
> 
> datDate          sngAmount
> 01.01.09          1000
> 15.02.09          -200
> 30.06.09          5000
> 30.06.09          -2000
> 
> The result looks like this:
> 
> datDate          sngAmount          Running total
> 01.01.09          1000                   1000
> 15.02.09          -200                     800
> 30.06.09          5000                   3800 (this should be 5800)
> 30.06.09          -2000                  3800
> 
> The third row should give me a value of 5800, the rest is fine.
> Instead, the third row is already the sum of the two numbers for the
> 30.06.09 (5000-2000=3000).
> 
> How am I supposed to adjust the formula to incorporate different
> values for the same date?
> 
> Regards,
> Andreas
> .
> 
0
Utf
12/29/2009 8:33:02 PM
On Tue, 29 Dec 2009 11:29:19 -0800 (PST), Andreas <andreas.vester@gmail.com>
wrote:

>Hello all,
>
>I am calculating a running sum within a query using the DSum function.
>
>DSum("[sngAmount]";"[tblAccountMovements]";"STR(CDBL([datDate]))<=" &
>Str(CDBL([datDate])))
>
>sngAmount contains positve or negative numbers from the table
>"tblAccountMovements".
>"datDate" is a date field from the same table.
>
>I would like to calculate a running total within a query that is
>sorted by "datDate". Basically, the above formula works fine. However,
>there arise problems if datDate contains a date several times. If this
>is the case, the calculation in the query gives me the total for the
>whole day in every record with the specific date.
>
>Here's an example:
>
>tblAccountMovements
>
>datDate          sngAmount
>01.01.09          1000
>15.02.09          -200
>30.06.09          5000
>30.06.09          -2000
>
>The result looks like this:
>
>datDate          sngAmount          Running total
>01.01.09          1000                   1000
>15.02.09          -200                     800
>30.06.09          5000                   3800 (this should be 5800)
>30.06.09          -2000                  3800
>
>The third row should give me a value of 5800, the rest is fine.
>Instead, the third row is already the sum of the two numbers for the
>30.06.09 (5000-2000=3000).
>
>How am I supposed to adjust the formula to incorporate different
>values for the same date?

Do you have some other field, such as an Autonumber, which would let you
distinguish different records from the same date?
-- 

             John W. Vinson [MVP]
0
John
12/29/2009 10:20:56 PM
If the table includes a primary key column you can use that to arbitrarily
distinguish between two transactions on the same day.  Here's an example for
a Transactions table with a key TrransactionID:

SELECT TransactionDate, Amount,
DSUM("Amount","Transactions","TransactionDate  <=
    " & FORMAT(Transactions.TransactionDate,"\#yyyy-mm-dd\#") & "  
    AND (TransactionID <= " & Transactions.TransactionID & "  
    OR TransactionDate <> " & FORMAT(Transactions.TransactionDate,"\#yyyy-mm-
dd\#") & ")")
AS Balance
FROM Transactions
ORDER BY TransactionDate,TransactionID;

Note that the Transaction key values do not have to be incremental by date,
only distinct, so an autonumber will work.  The result table does not
necessarily reflect the actual order of transactions within a day, however,
as there is nothing in the data to say what this is.

Ken Sheridan
Stafford, England

Andreas wrote:
>Hello all,
>
>I am calculating a running sum within a query using the DSum function.
>
>DSum("[sngAmount]";"[tblAccountMovements]";"STR(CDBL([datDate]))<=" &
>Str(CDBL([datDate])))
>
>sngAmount contains positve or negative numbers from the table
>"tblAccountMovements".
>"datDate" is a date field from the same table.
>
>I would like to calculate a running total within a query that is
>sorted by "datDate". Basically, the above formula works fine. However,
>there arise problems if datDate contains a date several times. If this
>is the case, the calculation in the query gives me the total for the
>whole day in every record with the specific date.
>
>Here's an example:
>
>tblAccountMovements
>
>datDate          sngAmount
>01.01.09          1000
>15.02.09          -200
>30.06.09          5000
>30.06.09          -2000
>
>The result looks like this:
>
>datDate          sngAmount          Running total
>01.01.09          1000                   1000
>15.02.09          -200                     800
>30.06.09          5000                   3800 (this should be 5800)
>30.06.09          -2000                  3800
>
>The third row should give me a value of 5800, the rest is fine.
>Instead, the third row is already the sum of the two numbers for the
>30.06.09 (5000-2000=3000).
>
>How am I supposed to adjust the formula to incorporate different
>values for the same date?
>
>Regards,
>Andreas

-- 
Message posted via AccessMonster.com
http://www.accessmonster.com/Uwe/Forums.aspx/access/200912/1

0
KenSheridan
12/29/2009 10:32:01 PM
Hi Andreas,

Try creating the odometer example, and then see if you can apply the same 
logic to your application. I recommend using Method 2.

     Referring to a Field in the Previous Record or Next Record
     http://support.microsoft.com/kb/210504

Note: Disregard the "Acc2000" in the title of this KB article.

 
Tom Wickerath
Microsoft Access MVP
http://www.accessmvp.com/TWickerath/
__________________________________________

"Andreas" wrote:

> Hello all,
> 
> I am calculating a running sum within a query using the DSum function.
> 
> DSum("[sngAmount]";"[tblAccountMovements]";"STR(CDBL([datDate]))<=" &
> Str(CDBL([datDate])))
> 
> sngAmount contains positve or negative numbers from the table
> "tblAccountMovements".
> "datDate" is a date field from the same table.
> 
> I would like to calculate a running total within a query that is
> sorted by "datDate". Basically, the above formula works fine. However,
> there arise problems if datDate contains a date several times. If this
> is the case, the calculation in the query gives me the total for the
> whole day in every record with the specific date.
> 
> Here's an example:
> 
> tblAccountMovements
> 
> datDate          sngAmount
> 01.01.09          1000
> 15.02.09          -200
> 30.06.09          5000
> 30.06.09          -2000
> 
> The result looks like this:
> 
> datDate          sngAmount          Running total
> 01.01.09          1000                   1000
> 15.02.09          -200                     800
> 30.06.09          5000                   3800 (this should be 5800)
> 30.06.09          -2000                  3800
> 
> The third row should give me a value of 5800, the rest is fine.
> Instead, the third row is already the sum of the two numbers for the
> 30.06.09 (5000-2000=3000).
> 
> How am I supposed to adjust the formula to incorporate different
> values for the same date?
> 
> Regards,
> Andreas
0
Utf
12/29/2009 10:55:01 PM
Reply:

Similar Artilces:

DPM 2010 release dates
Hi, I was wondering if anyone could define what the current projected release dates for DPM 2010 are? I'm specifically looking for RC and RTM dates. I've heard that the RTM is now expected to ship in early summer and wanted to confirm. Here is an old information I gathered before. I am not sure it is still accurate. So lets wait for the DPM team's answer: http://santhoshsivarajan.blogspot.com/2009/12/dpm-2010-timeline.html -- Santhosh Sivarajan | MCTS, MCSE (W2K3/W2K/NT4), MCSA (W2K3/W2K/MSG), CCNA Houston, TX http://blogs.sivarajan.com/ http://publications...

creating rule based on date email received
I would like to create a rule to move message to a specific folder based on their received date - i.e. anything older than 7 days, move to this folder. Can rules be made based on a general date, or do you need to put in specific dates for it to work. I do not want to archive the email, just move it to a separate folder for later review. Any help is appreciated. Thanks! "Diana" said in news:6b0b01c3e69d$9d45ff10$a001280a@phx.gbl: > I would like to create a rule to move message to a > specific folder based on their received date - i.e. > anything older than 7 days, ...

Counting with multiple criteria
Would be grateful if someone can help me with this A B C D 8-9AM 9-10AM 1 CA03 ON CA03 OF 2 CA03 OF CA03 OF 3 CA03 ON CA03 TR 4 CA03 TR CA03 TR 5 CA05 OF CA04 OF 6 CA05 TR CA05 ON 7 CA04 OF CA05 TR Note: Column A-B has the same header row, and so does C-D I want to count in the range (A1:D7) - How many CA03 and TR: [the result should be 3] - How many CA03 and ON and OF: [the result should be 5] Thanks in advance for your help. Best regards, Thuy Assuming your table is in A1:D8, data in rows 2 to 8 (in A2:D8) > ...

SharePoint 2010 Beta expiry date
Is there any expiry date set on SP2010 Beta? If yes, where can I view that date? TIA J Justin here is the link you get the details on that http://blogs.msdn.com/ekraus/archive/2009/11/17/sharepoint-2010-beta-2-is-finally-here.aspx Justin Jeyaraj wrote: SharePoint 2010 Beta expiry date 28-Apr-10 Is there any expiry date set on SP2010 Beta? If yes, where can I view that date? TIA J Justin Previous Posts In This Thread: Submitted via EggHeadCafe - Software Developer Portal of Choice Free Online Courses Available for Eggheadcafe.com Users http://www...

Grouping mails by their date received
Hi there, I would like to group my mails on "Received" date so as to figure out my activities on a particular date. Microsoft Outlook 2K SR1 allows its users to format the columns the way they want and group mails by those columns (except columns with formula) When I customize the "Received" column with "mm/dd/yy" format and group by it, Outlook falls back to the original format ignoring my customization. This results in a useless view in which Outlook groups the mails upto minutes accuracy and ends up puting one mail on each group and creating as many groups ...

RMS should have a search strategy for "date account opened"
EOM ---------------- This post is a suggestion for Microsoft, and Microsoft responds to the suggestions with the most votes. To vote for this suggestion, click the "I Agree" button in the message pane. If you do not see the button, follow this link to open the suggestion in the Microsoft Web-based Newsreader and then click "I Agree" in the message pane. http://www.microsoft.com/Businesssolutions/Community/NewsGroups/dgbrowser/en-us/default.mspx?mid=0b38650c-32cb-40cb-8b52-e4aab95e11f9&dg=microsoft.public.pos you can do this with reports. "samax" <s...

Vba Date$
I have to use the Date$, and this seems to be swapping the day and month: The system date is 04/06/2010 (dd/mm/yy), and the regional setting are for the UK when I try Dstr = Format(Date$, "dd/mm/yy"), I get 06/04/2010, and when I break it down into individual elements, ie Y = Year(Date$) M = Month(Date$) D = Day(Date$) I get M = 4 & D = 6! Please help! -- Eric Try using DStr = Format(Date, "dd/mm/yy") -- HTH Bob "Eric" <Eric@discussions.microsoft.com> wrote in message news:A93C4128-4E48-46B3-A59B-3...

automatically saving a workbook as today's date
I have set up a template and run a macro that copies information fro one workbook to another, then saves the changes and then closes. Thi is fine, but before the workbook closes I am trying to get the macro t rename the template with today's date, but without success. I have pu =today() in cell a1 and try to get the vba to look at this cell befor closing but it just saves the template as (a1).xls instead of today' date. Does anyone know what I am doing wrong. Your help will be gratefully received regards Steve Jackso -- Message posted from http://www.ExcelForum.com One way: ...

How do I enter a date in excel without "/" ex. 041504 will show 0.
Excel can't do this without some help. You could look at: http://www.xldynamic.com/source/xld.QDEDownload.html for an addin that can set this up. tj "Amy" wrote: > ...

Date Filtering in RMS Active Reports
My company is open past midnight. This causes terrible headaches for me and reporting since RMS uses the standard 24 hour day, yet I need sales that occur after midnight but prior to 3 am to appear on reports for the previous day. I have a datetime field that I am converting using the formula Formula = "CONVERT(nvarchar, ViewTenders.Time, 22)" so that in the active report it looks like 11/08/06 1:54:00 PM. In the active report, it's vbDataType is defined as vbString. I can not get the filter(s) to allow me to show dates correctly. What I'd like to see is all transa...

Languages in date colomn
After downloading my email through a swedish network, the weekdays and dates of recieved emails are stated in swedish in my inbox. My Outlook 2000 is Norwegian language. How can just this colomn change language, and is there a way for me to change it back to Norwegian ? Thank you in advance. anonymous@discussions.microsoft.com <anonymous@discussions.microsoft.com> wrote: > How can just this colomn change language, I don't know, but I've heard of it. > and is there a > way for me to change it back to Norwegian ? Here's something to try: at a command line pr...

Always future dates
I have a form with an unbound text box for entering a date. The text box's format property is set to Short Date. Here's the problem, based on today (09/14/07): If a user enters 01/15 into the text box, Access will expand that date to 01/15/07. The users would like the date to be expanded to 01/15/08, the future date instead of one in the past. Can someone suggest the easiest way to force the date into the future? Is there some sort of formatting property I can set, or would this need to be done in code? If it's in code, have you seen a sample anywhere that would give me a good sta...

=DATEDIF(start date,end date, unit)
When I use this function, the error #NAME? is returned. Could this because the function requires an ADD-IN or extra components installed? DATEDIF is described in my version of HELP but I notice it is not shown in the list of functions that appears when I select "Paste Function" from the toolbar and select the category "Date&Time". This is why I think perhaps the problem is that support is not installed. I'm using Excel 2000 V9.0.2720 Yes, tools>addins>analysis toolpak -- Don Guillett SalesAid Software donaldb@281.com "gvm" <postbox@tech...

Bold dates on yearly calendar
I am creating a yearly calendar using a publisher template. How can I bold certain dates on the calendar? When I click on a particular month, all the text for that month gets selected. Thank You About the only way I know is to select the month text box, copy, paste special as a table. The table will be large but can be resized to the same size as the text box by using the size handles. As for the month name cell... select the top row of the table, Table menu, merge cells. You should be able to bold the dates now. -- Mary Sauer http://msauer.mvps.org/ "Ana24" <Ana24@disc...

Count by short date and group by agent name
I have a tracking table (tbl_Tracker) that now contains date and time in one field [Date] and agent name in another field [SLR]. I would like run a query to do a count of number of records by agent by day. How do I set up the query to recognize only the date and not the time. I have Group By [SLR], Count [SLR] and Group By [Date], however it shows a record for each date and specific time instead of grouping the whole day. Then I need to build another query that looks at another table (tbl_SL_Call_Stats) for number of calls handled [Handled] by day [Date] for a date range and ...

Querry Criteria
Hellooo Monsters! I have a report that is based on a querry. The querry has two fields, StartMeter and EndMeter. I have a form with two textfields, txtSartMeter and txtEndMeter where I enter a value for start meter and end meter and a button to open the report. I would like to set the criteria in the querry under StartMeter and EndMeter to reffer to these two text boxes respetively and filter the report for records starting from the StartMeter and ending with EndMeter. In other words records between txtStartMeter and EndMeter. I know how to do this under one field, but don't know how if...

Report Generation Variables for Date
I'm trying to define a filter in a report, using the last month start and last month end as low and high limits. Can somebody tell me the name of this variables, like <Today> is self explanable. -- alvaroguzman this is all I have: <MonthStart> first day of month <WeekStart> date of first day of this week <LastWeekStart> date of first day of last week <YearStart> first day of year <Now> current date/time <ReportDate> date of report "Alvaro Guzman" <aguzmanc2005@hotmail.com> wrote in message news:7C2DA569-6C0C-420C-9F49-4FC...

Conditional Formatting Dates 02-18-10
I am attempting to highlight past due dates (I am horrible with the formula's and can not seem to figure out how to NOT highlight if there is no information in the cell's) A1=Planned date and A2=Completed date Conditions I am trying to figure out 1. Would like A1 to highlight RED if less than Now and A1 is NOT BLANK or A2 is BLANK 2. Would like A2 to highlight green if filled out and less than or equal to A1 Thanks anyone that can help!!! Katie CF formula for A1: =OR(ISBLANK(A2),AND(A1<TODAY(),ISNUMBER(A1))) CF formula for A2: =AND(ISNUMBER(A2),A2<=A1...

Data Validation With Multiple Criteria
I currently have a form that accepts sample measurements. Is there a way to place multiple validation rules into a text box so that there is either a measurement entered between 4" and 4.5" or the text box is left empty as the other choice. (This last option would be to allow a person who accidentally entered a measurement into the wrong text box to go back and delete it without breaking the validation rule ) I'd greatly appreciate any advice on the best way to do this, Thanks, Adam Private Sub YourTextBox_BeforeUpdate(Cancel As Integer) If Not IsNull(Me.Yo...

Last Meeting Date
I am looking for a way to populate the last meeting date into a custom field of a contact entity. I did not see how to do this with the MS Workflow. You can't do that from workflow unless you going to write a workflow assemly to pull the information through web service or filtered views. Are you familiar with the CRM 3.0 SDK? Darren Liu Crowe Chizek and Company http://www.crowecrm.com On Mar 30, 10:10 am, "tim" <computerti...@gmail.com> wrote: > I am looking for a way to populate the last meeting date into a custom > field of a contact entity. I did not see how...

Check inputdate, then retrieve data to fill in chart from dated co
ok hope I can explain this.. I have a sheet with dated columns and the first row is employee names each dated column is filled with letters that correspond to a duty a-g. so for the next 3 months I can look across the top for a date then down the column to see where each person is supposed to be. Now I also have a form I print up daily to post for people to see where they are supposed to be.. I fill it manually at this point I wonder if there is any formulat to help automate this.. I am thinking two hopeful ideas.. a drop down list on the form, pulling the list of names......

Downloaded Date Wrong
When I'm viewing a specific account, in the upper left pane is the DOWNLOADED information; date, balance and items to review. For some reason, tha date, balance etc. is no longer being updated when I download statments from my bank. Any ideas how to get that nice feature back up and running? I think that one comes from your bank in the downloaded file, so you need to ask them or choose OFX as the download format if that is an option for you,. -- Glyn Simpson, Microsoft MVP - Money Check http://support.microsoft.com/default.aspx?scid=fh;EN-GB;mny for UK tips and fixes for MS Mon...

Save as date on exit
im currently working on a "cashout" sheet in which different ppl enter their data and do the cashout accordingly. right now - the sheets are all being saved as hard copies and the information entered in the spread sheet is not saved and the next person carries on as described. what the owner of the company would like is an auto back-up of this proceedure, where as the data entered into the spread sheet is saved after the current session is closed. im not too sure how to correctly describe what i need - but i think that's it... instead of not saving the data - the data will...

Textbox Code for Date Format
Pretty sure it's something silly on my part. form contain combobox 'Date' (It looks up dates from specified dates within payroll timeframes) No-Control text box placed next to combo box to have Day of Week appear to keep people on right day. (I don't like the calendar idea, because I need to keep people in the correct payroll date range and other items.) For text box, from property window / data tab / control source I've entered =Formate([Date],"dddd") expecting the day of the week to appear on focus. Field populates fine but shows wrong day of th...

Date Validation pop up
Hi Everyone, I was just asked to create a date validation pop up on a form that I'm designing. The validation is a pop up box that asks the user if the end date of the period is correct by taking the last date of the previous period and adding the number of days in the current period. So one field on the form asks for the end date of the last report period and another field asks for the number of days in the current period. For example the last day of the previous review period could be April 30, 2007 and the number of days in the current period is 7 days. So they would like a pop up t...