Query calculating fiscal year and total days used (1 Viewer)

Sketchin

Registered User.
Local time
Today, 11:57
Joined
Dec 20, 2011
Messages
575
Hey All, I have been banging my head on the desk for hours now trying to figure this one out.

I have a query that shows me what fiscal year my equipment reservations fall on, based on a fiscal year of april 1st 2011 to march 31 2012 (for example). It also calculates total days usage.

I then have a report based on this query where I have a query parameter asking me to enter which fiscal year I want to display. This is all working fine. My problem is when I have a reservation that starts in fiscal year 2012 and ends in fiscal year 2013. Ill try to illustrate what I am talking about:

Reservation dates: DateOutReq = 01/11/2011 DateInReq = 31/12/2012

My total days usage end up being:

Fiscal year Total Days used From date To Date
2012 427 01/11/2011 31/12/2012

My problem is that the query is doing exactly what I'm telling it to, but for fiscal 2012 I would like total days used to be from 01/11/2011 to 31/03/2012 and I would like it to also show fiscal 2013 to be the remaining days for Fiscal 2013 (from 01/04/2012 to 31/12/2012)

Below is the SQL from my query:
Code:
SELECT DISTINCT tblBOM_Master.BOMDescription, Year([DateOutReq])-IIf([DateoutReq]<DateSerial(Year([DateOutReq]),4,1),1,0)+1 AS Fiscal, Sum(DateDiff("d",[DateOutReq],[DateInReq])+1) AS [Total Usage Days], tblReservations.DateOutReq, tblReservations.DateInReq
FROM tblReservations INNER JOIN (tblBOM_Master INNER JOIN tblReservation_details ON tblBOM_Master.BOMID = tblReservation_details.BOMNumber) ON tblReservations.ReservationID = tblReservation_details.ReservationID
GROUP BY tblBOM_Master.BOMDescription, Year([DateOutReq])-IIf([DateoutReq]<DateSerial(Year([DateOutReq]),4,1),1,0)+1, tblReservations.DateOutReq, tblReservations.DateInReq
HAVING (((Year([DateOutReq])-IIf([DateoutReq]<DateSerial(Year([DateOutReq]),4,1),1,0)+1)=[Enter Fiscal Year]));

Thanks for any and all suggestions, I am hoping i am just overlooking an obvious solution!
 

Users who are viewing this thread

Top Bottom