Solved

access query fiscal year

Posted on 2007-03-22
7
1,294 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
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 
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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

I originally created this report in Crystal Reports 2008 where there is an option to underlay sections. I initially came across the problem in Access Reports where I was unable to run my border lines down through the entire page as I was using the P…
Composite queries are used to retrieve the results from joining multiple queries after applying any filters. UNION, INTERSECT, MINUS, and UNION ALL are some of the operators used to get certain desired results.​
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…
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.

747 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

9 Experts available now in Live!

Get 1:1 Help Now