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
7
Medium Priority
?
1,343 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
[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
  • Learn & ask questions
  • 4
7 Comments
 
LVL 66

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
Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

 
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 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

Moving data to the cloud? Find out if you’re ready

Before moving to the cloud, it is important to carefully define your db needs, plan for the migration & understand prod. environment. This wp explains how to define what you need from a cloud provider, plan for the migration & what putting a cloud solution into practice entails.

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 …

715 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