Solved

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

Posted on 2004-08-31
6
272 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
Comment Utility
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
Comment Utility
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
Comment Utility
That's why [Ocurrence Value] is enclosed between brackets. It would work, though.

Good luck.
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 3

Author Comment

by:tthayer
Comment Utility
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
Comment Utility
Got it!  Changed the format on the report.
0
 
LVL 16

Expert Comment

by:Nestorio
Comment Utility
Glad to have helped.
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Most if not all databases provide tools to filter data; even simple mail-merge programs might offer basic filtering capabilities. This is so important that, although Access has many built-in features to help the user in this task, developers often n…
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…
Familiarize people with the process of utilizing SQL Server stored procedures 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 Micr…
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…

772 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

12 Experts available now in Live!

Get 1:1 Help Now