PC Review


Reply
Thread Tools Rate Thread

DSum Works Only for First Group

 
 
Elizabeth Gallagher
Guest
Posts: n/a
 
      3rd Oct 2010
The Query:
SELECT Test.Bname, Test.Week, Sum(Test.SCount) AS SumOfSCount,
DSum("scount","test","(iif([bname]='a',[bname],[bname]))<='" & [bname]
& "' And iif([week]=now,[week],[week])<=#" & [week] & "#") AS RunTot
FROM Test
GROUP BY Test.Bname, Test.Week
ORDER BY Test.Bname, Test.Week;

The Current Result:
Bname Week SumOfSCount RunTot
F 9/26/2010 4 4
F 10/3/2010 3 7
F 10/10/2010 1 8
O 9/26/2010 9 13
O 10/3/2010 3 19
O 10/10/2010 12 32

The Desired Result:
Bname Week SumOfSCount RunTot
F 9/26/2010 4 4
F 10/3/2010 3 7
F 10/10/2010 1 8
O 9/26/2010 9 9
O 10/3/2010 3 12
O 10/10/2010 12 24

Does anyoe have any questions? I am willing to do a subquery if
necessary but I am not sure if that would help.
 
Reply With Quote
 
 
 
 
John W. Vinson
Guest
Posts: n/a
 
      3rd Oct 2010
On Sun, 3 Oct 2010 13:16:40 -0700 (PDT), Elizabeth Gallagher
<(E-Mail Removed)> wrote:

>The Query:
>SELECT Test.Bname, Test.Week, Sum(Test.SCount) AS SumOfSCount,
>DSum("scount","test","(iif([bname]='a',[bname],[bname]))<='" & [bname]
>& "' And iif([week]=now,[week],[week])<=#" & [week] & "#") AS RunTot
>FROM Test
>GROUP BY Test.Bname, Test.Week
>ORDER BY Test.Bname, Test.Week;
>
>The Current Result:
>Bname Week SumOfSCount RunTot
>F 9/26/2010 4 4
>F 10/3/2010 3 7
>F 10/10/2010 1 8
>O 9/26/2010 9 13
>O 10/3/2010 3 19
>O 10/10/2010 12 32
>
>The Desired Result:
>Bname Week SumOfSCount RunTot
>F 9/26/2010 4 4
>F 10/3/2010 3 7
>F 10/10/2010 1 8
>O 9/26/2010 9 9
>O 10/3/2010 3 12
>O 10/10/2010 12 24
>
>Does anyoe have any questions? I am willing to do a subquery if
>necessary but I am not sure if that would help.


Now() does not return today's date; it returns the current date and time
accurate to microseconds, so it's very unlikely indeed that [Week] will be
equal to Now. I suspect you might want to try Date() instead of Now().

In addition, your first IIf statement makes no sense. It says

If [bname] is equal to "A" return the value of [bname]
If [bname] is not equal to "A" return the value of [bname]

in other words, just use [bname].

Could you explain the logic?
--

John W. Vinson [MVP]
Microsoft's replacements for these newsgroups:
http://social.msdn.microsoft.com/For...-US/accessdev/
http://social.answers.microsoft.com/.../en-US/addbuz/
and see also http://www.utteraccess.com
 
Reply With Quote
 
Elizabeth Gallagher
Guest
Posts: n/a
 
      3rd Oct 2010
On Oct 3, 4:36*pm, John W. Vinson <jvinson@STOP_SPAM.WysardOfInfo.com>
wrote:
> On Sun, 3 Oct 2010 13:16:40 -0700 (PDT), Elizabeth Gallagher
>
>
>
>
>
> <emgallaghe...@gmail.com> wrote:
> >The Query:
> >SELECT Test.Bname, Test.Week, Sum(Test.SCount) AS SumOfSCount,
> >DSum("scount","test","(iif([bname]='a',[bname],[bname]))<='" & [bname]
> >& "' And iif([week]=now,[week],[week])<=#" & [week] & "#") AS RunTot
> >FROM Test
> >GROUP BY Test.Bname, Test.Week
> >ORDER BY Test.Bname, Test.Week;

>
> >The Current Result:
> >Bname * * * Week * *SumOfSCount * * RunTot
> >F * 9/26/2010 * * * * * *4 * * * * * * * **4
> >F * 10/3/2010 * * * * * *3 * * * * * * * **7
> >F * 10/10/2010 * * 1 * * * * * * * * * * * *8
> >O * 9/26/2010 * * * * * *9 * * * * * * * **13
> >O * 10/3/2010 * * * * * *3 * * * * * * * **19
> >O * 10/10/2010 * * 12 * * * * * * * * * * * *32

>
> >The Desired Result:
> >Bname * * * Week * *SumOfSCount * * RunTot
> >F * 9/26/2010 * * * * * *4 * * * * * * * **4
> >F * 10/3/2010 * * * * * *3 * * * * * * * **7
> >F * 10/10/2010 * * 1 * * * * * * * * * * * *8
> >O * 9/26/2010 * * * * * *9 * * * * * * * **9
> >O * 10/3/2010 * * * * * *3 * * * * * * * **12
> >O * 10/10/2010 * * 12 * * * * * * * * * * * *24

>
> >Does anyoe have any questions? *I am willing to do a subquery if
> >necessary but I am not sure if that would help.

>
> Now() does not return today's date; it returns the current date and time
> accurate to microseconds, so it's very unlikely indeed that [Week] will be
> equal to Now. I suspect you might want to try Date() instead of Now().
>
> In addition, your first IIf statement makes no sense. It says
>
> If [bname] is equal to "A" return the value of [bname]
> If [bname] is not equal to "A" return the value of [bname]
>
> in other words, just use [bname].
>
> Could you explain the logic?
> --
>
> * * * * * * *John W. Vinson [MVP]
> *Microsoft's replacements for these newsgroups:
> *http://social.msdn.microsoft.com/For...-US/accessdev/
> *http://social.answers.microsoft.com/.../en-US/addbuz/
> *and see alsohttp://www.utteraccess.com- Hide quoted text -
>
> - Show quoted text -


I was using those logic statements because it didn't seem to work if I
just used ([week]<=#" & [week] & "#"). I tried including a field
called [weeknew] and doing ([week]<=#" & [weeknew] & "#") but that
didn't seem to work either.

In any case, I was doing more google searches (even though I searched
for hours before posting), and finally found the answer. I was able
to use a subquery to accomplish what I needed:

SELECT a.bname, a.Week, a.SCount, scount+nz((select sum(scount) from
test b where b.ID<a.ID and b.bname=a.bname),0) AS ['Running Total']
FROM test AS a;

Thanks for considering my question!
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
DSum by group =?Utf-8?B?UnVzc0c=?= Microsoft Access Reports 3 15th Mar 2007 03:39 PM
DSUM in Group Footer =?Utf-8?B?RGFuIFMu?= Microsoft Access Reports 6 28th Mar 2006 07:55 PM
Dsum() works sometimes =?Utf-8?B?Sm9obm55IEJyaWdodA==?= Microsoft Access Form Coding 2 10th Jun 2005 06:50 AM
DSUM only works if reference workbook is open Jen Microsoft Excel Worksheet Functions 1 14th Jul 2004 10:11 PM
Re: Dsum with a group John Vinson Microsoft Access 0 16th Apr 2004 06:42 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 04:36 PM.