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 » Setting Up & Running Reports
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

Calculate records with dates from past week and month



 
 
Thread Tools Display Modes
  #1  
Old December 14th, 2009, 12:33 AM posted to microsoft.public.access.reports
Teddy
external usenet poster
 
Posts: 47
Default Calculate records with dates from past week and month

I have a table in which each record has an action date. I’d like to create a
report with two fields. One field will calculate the number of records with
dates from the past week. The second field will calculate the number of
records with dates from the past month. Can you tell me how to do that?
  #2  
Old December 14th, 2009, 01:56 PM posted to microsoft.public.access.reports
Jeff Boyce
external usenet poster
 
Posts: 1,555
Default Calculate records with dates from past week and month

Teddy

Remember that reports have "controls" (tables have "fields") that can
display data. That data can come from tables or queries, or could come from
an expression.

You could use an expression in a control that calculated the number of
records within "the past week" (more definition, please), and another for
within "the past month". One approach might be to look at the DCount()
function.

Good luck!

--

Regards

Jeff Boyce
Microsoft Access MVP

Disclaimer: This author may have received products and services mentioned in
this post. Mention and/or description of a product or service herein does
not constitute endorsement thereof.

Any code or pseudocode included in this post is offered "as is", with no
guarantee as to suitability.

You can thank the FTC of the USA for making this disclaimer
possible/necessary.

"Teddy" wrote in message
...
I have a table in which each record has an action date. I'd like to create
a
report with two fields. One field will calculate the number of records
with
dates from the past week. The second field will calculate the number of
records with dates from the past month. Can you tell me how to do that?



  #3  
Old December 14th, 2009, 02:02 PM posted to microsoft.public.access.reports
Dale Fye
external usenet poster
 
Posts: 2,651
Default Calculate records with dates from past week and month


Something like this should work:

SELECT SUM(IIF([DateField] BETWEEN DateAdd("d", -7, Date()) AND Date(), 1,
0)) as PastWeek,
SUM(IIF([DateField] BETWEEN DateAdd("m", -1, Date()) AND Date(), 1, 0)) as
PastMonth
FROM yourtable

This uses the current date as the base for PastWeek and PastMonth. If you
actually want LastMonth and LastWeek, you will probably need to use the
DateSerial function.
----
HTH
Dale



"Teddy" wrote:

I have a table in which each record has an action date. I’d like to create a
report with two fields. One field will calculate the number of records with
dates from the past week. The second field will calculate the number of
records with dates from the past month. Can you tell me how to do that?

  #4  
Old December 16th, 2009, 01:41 AM posted to microsoft.public.access.reports
Teddy
external usenet poster
 
Posts: 47
Default Calculate records with dates from past week and month

This is perfect. Thank you Dale!

"Dale Fye" wrote:


Something like this should work:

SELECT SUM(IIF([DateField] BETWEEN DateAdd("d", -7, Date()) AND Date(), 1,
0)) as PastWeek,
SUM(IIF([DateField] BETWEEN DateAdd("m", -1, Date()) AND Date(), 1, 0)) as
PastMonth
FROM yourtable

This uses the current date as the base for PastWeek and PastMonth. If you
actually want LastMonth and LastWeek, you will probably need to use the
DateSerial function.
----
HTH
Dale



"Teddy" wrote:

I have a table in which each record has an action date. I’d like to create a
report with two fields. One field will calculate the number of records with
dates from the past week. The second field will calculate the number of
records with dates from the past month. Can you tell me how to do that?

  #5  
Old December 16th, 2009, 01:42 AM posted to microsoft.public.access.reports
Teddy
external usenet poster
 
Posts: 47
Default Calculate records with dates from past week and month

Jeff that is helpful. Thank you for clarifying that for me. I appreciate
your feedback.

"Jeff Boyce" wrote:

Teddy

Remember that reports have "controls" (tables have "fields") that can
display data. That data can come from tables or queries, or could come from
an expression.

You could use an expression in a control that calculated the number of
records within "the past week" (more definition, please), and another for
within "the past month". One approach might be to look at the DCount()
function.

Good luck!

--

Regards

Jeff Boyce
Microsoft Access MVP

Disclaimer: This author may have received products and services mentioned in
this post. Mention and/or description of a product or service herein does
not constitute endorsement thereof.

Any code or pseudocode included in this post is offered "as is", with no
guarantee as to suitability.

You can thank the FTC of the USA for making this disclaimer
possible/necessary.

"Teddy" wrote in message
...
I have a table in which each record has an action date. I'd like to create
a
report with two fields. One field will calculate the number of records
with
dates from the past week. The second field will calculate the number of
records with dates from the past month. Can you tell me how to do that?



.

 




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 05:02 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.