Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
Solved

access query fiscal year

Posted on 2007-03-22
Medium Priority
1,343 Views
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
Question by:Kurt4949
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

• Help others & share knowledge
• Earn cash & points
• 4

LVL 66

Expert Comment

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

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

LVL 44

Expert Comment

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

LVL 44

Expert Comment

ID: 18776441
Hi Jim.
0

LVL 7

Author Comment

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

GRayL earned 2000 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

Question has a verified solution.

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

Access custom database properties are useful for storing miscellaneous bits of information in a format that persists through database closing and reopening.  This article shows how to create and use them.
The Windows Phone Theme Colours is a tight, powerful, and well balanced palette. This tiny Access application makes it a snap to select and pick a value. And it doubles as an intro to implementing WithEvents, one of Access' hidden gems.
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.
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …
Suggested Courses
Course of the Month8 days, 2 hours left to enroll