Solved

access query fiscal year

Posted on 2007-03-22
7
1,313 Views
Last Modified: 2012-10-11
How do I modify the below query to select data from the current and last fiscal year instead of calendar year?


SELECT DISTINCT t1.qProductCategory,
    (SELECT SUM(t2.qQuantity)

    FROM YourTable AS t2
    WHERE t2.qProductCategory = t1.qProductCategory AND
    Year(t2.qDate) = Year(now) -1 ) AS Pre1_Qty,
    (SELECT SUM(t2.qQValue)

    FROM YourTable AS t2
    WHERE t2.qProductCategory = t1.qProductCategory AND
    Year(t2.qDate) = Year(now) -1 ) AS Pre1_Value,
    (SELECT SUM(t2.qQuantity)

    FROM YourTable AS t2
    WHERE t2.qProductCategory = t1.qProductCategory AND
    Year(t2.qDate) = Year(now)) AS Now_Qty,
    (SELECT SUM(t2.qQValue)

    FROM YourTable AS t2
    WHERE t2.qProductCategory = t1.qProductCategory AND
    Year(t2.qDate) = Year(now)) AS Now_Value


FROM YourTable AS t1
0
Comment
Question by:Kurt4949
  • 4
7 Comments
 
LVL 65

Expert Comment

by:Jim Horn
ID: 18774999
Define 'fiscal year' for us.  You'll likely need to populate a table of months (weeks, days) so that Access knows as well.
0
 
LVL 44

Expert Comment

by:GRayL
ID: 18776243
If you mean like the US DoD FY Oct to Sep?
0
 
LVL 44

Expert Comment

by:GRayL
ID: 18776430
Try this:

SELECT DISTINCT t1.qProductCategory,
    (SELECT SUM(t2.qQuantity)

    FROM YourTable AS t2
    WHERE t2.qProductCategory = t1.qProductCategory AND
    iif(Month(qdate)<10,Year(qdate),Year(qdate)+1) =  
    iif(Month(date)<10,Year(date),Year(date)+1) -1 ) AS Pre1_Qty,
    (SELECT SUM(t2.qQValue)

    FROM YourTable AS t2
    WHERE t2.qProductCategory = t1.qProductCategory AND
    iif(Month(qdate)<10,Year(qdate),Year(qdate)+1) =
    iif(Month(date)<10,Year(date),Year(date)+1) -1 ) AS Pre1_Value,
    (SELECT SUM(t2.qQuantity)

    FROM YourTable AS t2
    WHERE t2.qProductCategory = t1.qProductCategory AND
    iif(Month(qdate)<10,Year(qdate),Year(qdate)+1) =
    iif(Month(date)<10,Year(date),Year(date)+1)) AS Now_Qty,
    (SELECT SUM(t2.qQValue)

    FROM YourTable AS t2
    WHERE t2.qProductCategory = t1.qProductCategory AND
    iif(Month(qdate)<10,Year(qdate),Year(qdate)+1) =
    iif(Month(date)<10,Year(date),Year(date)+1)) AS Now_Value


FROM YourTable AS t1;

0
Resolve Critical IT Incidents Fast

If your data, services or processes become compromised, your organization can suffer damage in just minutes and how fast you communicate during a major IT incident is everything. Learn how to immediately identify incidents & best practices to resolve them quickly and effectively.

 
LVL 44

Expert Comment

by:GRayL
ID: 18776441
Hi Jim.
0
 
LVL 7

Author Comment

by:Kurt4949
ID: 18792648
fiscal year means the year ends in lets say November 31st instead of December 31st.  I haven't tried your solution GRayL but I will later today.  Could you briefly explain whats happening there?
0
 
LVL 44

Accepted Solution

by:
GRayL earned 500 total points
ID: 18794175
In this expression, it returns the year of the qdate and date values if the month is less than 10, else it adds one to the year.

    iif(Month(qdate)<10,Year(qdate),Year(qdate)+1) =  
    iif(Month(date)<10,Year(date),Year(date)+1) -1 ) AS Pre1_Qty,

To use a FY 1 Dec thru 30 Nov the following year (my calendar says November has 30 days, not 31!), you would replace the 10's with 12's.

IOW, I used your original query which gave you (I presume) the results you wanted for a calendar year (CY), and subsituted the FY function in place of the CY calls.  In my example it would report on a FY defined as 1 Oct thru 31 Sep the following year.
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Overview: This article:       (a) explains one principle method to cross-reference invoice items in Quickbooks®       (b) explores the reasons one might need to cross-reference invoice items       (c) provides a sample process for creating a M…
It’s been over a month into 2017, and there is already a sophisticated Gmail phishing email making it rounds. New techniques and tactics, have given hackers a way to authentically impersonate your contacts.How it Works The attack works by targeti…
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…

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