Solved

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

Posted on 2004-08-31
6
275 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
Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

 
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

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Question has a verified solution.

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

I see at least one EE question a week that pertains to using temporary tables in MS Access.  But surprisingly, I was unable to find a single article devoted solely to this topic. I don’t intend to describe all of the uses of temporary tables in t…
Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
Familiarize people with the process of utilizing SQL Server views from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Access…
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…

896 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now