Solved

access query fiscal year

Posted on 2007-03-22
7
1,308 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
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 
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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Occasionally there is a need to clean table columns, especially if you have inherited legacy data. There are obviously many ways to accomplish that, including elaborate UPDATE queries with anywhere from one to numerous REPLACE functions (even within…
As tax season makes its return, so does the increase in cyber crime and tax refund phishing that comes with it
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…

822 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