A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Access » Running & Setting Up Queries
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

Total by certain time period



 
 
Thread Tools Display Modes
  #1  
Old June 4th, 2010, 04:02 AM posted to microsoft.public.access.queries
nadesico
external usenet poster
 
Posts: 9
Default Total by certain time period

I have three fields in a table, and want to determine the total of the
occurrences by a certain time period. The data I have looks like this.

FGC RDate Occurrences
81 2009/01 1
81 2009/02 1
81 2009/03 1
81 2009/04 1
81 2009/05 5
81 2009/06 84
81 2009/07 1
81 2009/08 6
81 2009/09 3
81 2009/10 1
81 2009/11 5

And I want it to look like this

FGC 81

Less Than 3 Months 9
3 Or More Months 91
6 Or More Months 7
9 Or More Months 2
12 Or More Months 0

The month that the results are based off of is 2009/11. For this example, I
am using a specific month, but for future use the month will be determined by
Date() converted to yyyy/mm.
Any help would be greatly appreciated.

Thanks

  #2  
Old June 4th, 2010, 04:58 AM posted to microsoft.public.access.queries
PieterLinden via AccessMonster.com
external usenet poster
 
Posts: 307
Default Total by certain time period

First off, you have to use DateDiff() to determine the number of time units
between the two dates.

e.g.
DateDiff("q", FirstDate, SecondDate) will return the number of quarters
between FirstDate and SecondDate. Then you can use switch to

nadesico wrote:
I have three fields in a table, and want to determine the total of the
occurrences by a certain time period. The data I have looks like this.

FGC RDate Occurrences
81 2009/01 1
81 2009/02 1
81 2009/03 1
81 2009/04 1
81 2009/05 5
81 2009/06 84
81 2009/07 1
81 2009/08 6
81 2009/09 3
81 2009/10 1
81 2009/11 5

And I want it to look like this

FGC 81

Less Than 3 Months 9
3 Or More Months 91
6 Or More Months 7
9 Or More Months 2
12 Or More Months 0

The month that the results are based off of is 2009/11. For this example, I
am using a specific month, but for future use the month will be determined by
Date() converted to yyyy/mm.
Any help would be greatly appreciated.

Thanks


Do something like this:
SELECT tblDates.SomeDate, DateDiff("q",[SomeDate],Date()) AS QuartersAgo,
Switch([QuartersAgo]=0,"Less than 3 Months",[QuartersAgo]=1,"3 or More
Months",[QuartersAgo]=2,"6 Or More Months",[QuartersAgo]=3,"9 Or More Months",
[QuartersAgo]=4,"12 Or More Months",[QuartersAgo]=5,"15 Or More Months") AS
QuartersText
FROM tblDates;


Then create a query that groups by the QuartersText and does a count.

--
Message posted via http://www.accessmonster.com

 




Thread Tools
Display Modes

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

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 06:52 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.