Solved

Report to count up total occurrences by Employee from current quarter back 7 quarters.

Posted on 2004-08-31
6
280 Views
Last Modified: 2012-05-05
Objective
          I am trying to create a report to show an employee's total occurrences for the current quarter back 7 quarters.  I
          have had a lot of help but not quite there yet.  Where I am at is creating a query to get the information.

Rules to Calculate are below

          A quarter is a set date during a year.  The quarter ends March 31,  June 30, September 30, and December 31 for
          any given year.

          An employee's totals at the end of a quarter needs to be checked from the ending quarter back one year.  

Example  
          If I put in a quarter ending date of 6/30/04  the calculation for that period would be to start with that date and go
          back 364 days and total up the employee's occurrences.  Then I would bounce back to the prior quarter of 3/31/04
          and count back 364 days again until I have a total of 8 quarters.

Currently here is the code I think I am close with.  In the table tblOccurrence the date field is OccurrenceDate and the value I want to add up is in a field called OccurrenceValue.  I like this code because it asks me for a date to start with.

SELECT Employee,
sum(iif(datediff("m", [OccurrenceDate] - 1, dateadd("q", -7, dtRefDate)) between 1 and 12, 1, 0)) as [Quarter1],
sum(iif(datediff("m", [OccurrenceDate] - 1, dateadd("q", -6, dtRefDate)) between 1 and 12, 1, 0)) as [Quarter2],
sum(iif(datediff("m", [OccurrenceDate] - 1, dateadd("q", -5, dtRefDate)) between 1 and 12, 1, 0)) as [Quarter3],
sum(iif(datediff("m", [OccurrenceDate] - 1, dateadd("q", -4, dtRefDate)) between 1 and 12, 1, 0)) as [Quarter4],
sum(iif(datediff("m", [OccurrenceDate] - 1, dateadd("q", -3, dtRefDate)) between 1 and 12, 1, 0)) as [Quarter5],
sum(iif(datediff("m", [OccurrenceDate] - 1, dateadd("q", -2, dtRefDate)) between 1 and 12, 1, 0)) as [Quarter6],
sum(iif(datediff("m", [OccurrenceDate] - 1, dateadd("q", -1, dtRefDate)) between 1 and 12, 1, 0)) as [Quarter7],
sum(iif(datediff("m", [OccurrenceDate] - 1, dtRefDate) between 1 and 12, 1, 0)) as [Quarter8]
from tblOccurrence
group by Employee
0
Comment
Question by:tthayer
  • 3
  • 3
6 Comments
 
LVL 16

Accepted Solution

by:
Nestorio earned 500 total points
ID: 11948555
Hi TThayer,

Have you tried this query? It is not the same you posted above.

SELECT Employee,
sum(iif(datediff("m", [Occurrence Date] - 1, dateadd("q", -7, dtRefDate)) between 1 and 12, [Occurrence Value], 0)) as [Quarter1],
sum(iif(datediff("m", [Occurrence Date] - 1, dateadd("q", -6, dtRefDate)) between 1 and 12, [Occurrence Value], 0)) as [Quarter2],
sum(iif(datediff("m", [Occurrence Date] - 1, dateadd("q", -5, dtRefDate)) between 1 and 12, [Occurrence Value], 0)) as [Quarter3],
sum(iif(datediff("m", [Occurrence Date] - 1, dateadd("q", -4, dtRefDate)) between 1 and 12, [Occurrence Value], 0)) as [Quarter4],
sum(iif(datediff("m", [Occurrence Date] - 1, dateadd("q", -3, dtRefDate)) between 1 and 12, [Occurrence Value], 0)) as [Quarter5],
sum(iif(datediff("m", [Occurrence Date] - 1, dateadd("q", -2, dtRefDate)) between 1 and 12, [Occurrence Value], 0)) as [Quarter6],
sum(iif(datediff("m", [Occurrence Date] - 1, dateadd("q", -1, dtRefDate)) between 1 and 12, [Occurrence Value], 0)) as [Quarter7],
sum(iif(datediff("m", [Occurrence Date] - 1, dtRefDate) between 1 and 12, [Occurrence Value], 0)) as [Quarter8]
from tblOccurrence
group by Employee

Tell me if it works.

Regards
0
 
LVL 3

Author Comment

by:tthayer
ID: 11948591
Yee Ha!  Hoping you were out there.   I did try the other query but it asks for both a dtrefDate  and and Occurrence Value.  I am putting in 6/30/03 for the date but dont know what to put in for the value.  While typing this I just had a thought to check.  I have changed the Occurrence Date to one word OccurrenceDate and the Occurrence Value to One word OccurrenceValue.  I made the adjustments and it worked.  All the values came up as currency as I am using currency to get decimal values to show up on other forms.  Is there a way to just show numbers to 2 decimal places without the $ signs?

Here is what I got  the numbers are close to what I manually calculated but then I could have made some mistakes.  Numbers run together for me.

Employee      Quarter1      Quarter2      Quarter3      Quarter4      Quarter5      Quarter6      Quarter7      Quarter8
Ausmus, Adam      $0.00      $0.00      $0.00      $0.00      $0.00      $0.00      $0.00      $1.00
Thayer, Trygve      $4.00      $4.00      $5.00      $9.00      $10.00      $10.00      $9.00      $4.00
0
 
LVL 16

Expert Comment

by:Nestorio
ID: 11948706
That's why [Ocurrence Value] is enclosed between brackets. It would work, though.

Good luck.
0
Back Up Your Microsoft Windows Server®

Back up all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

 
LVL 3

Author Comment

by:tthayer
ID: 11948749
Thanks for your help.  I will try to work on getting rid of the $ signs but not sure where to start.
0
 
LVL 3

Author Comment

by:tthayer
ID: 11948763
Got it!  Changed the format on the report.
0
 
LVL 16

Expert Comment

by:Nestorio
ID: 11948814
Glad to have helped.
0

Featured Post

Ransomware: The New Cyber Threat & How to Stop It

This infographic explains ransomware, type of malware that blocks access to your files or your systems and holds them hostage until a ransom is paid. It also examines the different types of ransomware and explains what you can do to thwart this sinister online threat.  

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
As tax season makes its return, so does the increase in cyber crime and tax refund phishing that comes with it
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

856 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question