473,395 Members | 1,471 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Fiscal YTD vs. past year in Query criteria

craigfr
I am making a graph comparing last year's defect data with YTD defect data. Our fiscal year starts Nov.1 and ends Oct.31.
To get the YTD, I started used a simple date serial criteria:

Between DateSerial(Year(Date())-1,11,1) And Date()

This works, but only for 10 months out of the year. If your'e in December, it will calculate the YTD from last year's November to the current December, not the last November.

My solution was to make an IIF statement in the query criteria that calculated it differently if the current date is November or December:

IIf(Date()>DateSerial(Year(Date()),10,31),
Between DateSerial(Year(Date()),11,1) And Date(),
Between DateSerial(Year(Date())-1,11,1) And Date()


For some reason, this doesnt work. It returns 0 records every time I run it. I can run either one of the true/false statements by themselves and they work, as well as the IIF statement (with different T/F's) and it works.

Obviously this is only for the YTD, but I figure the past year's data query criteria will be very similar in design.

I'm not big on VB, so if this can be solved somehow in the basic query window that would be better; but I'm open to anything that works. Any ideas?
Sep 24 '07 #1
6 6268
FishVal
2,653 Expert 2GB
Hi, there.

Take a look at this thread
Year Formatting April-March
Sep 24 '07 #2
Thanks, I'm sure that will point me in the right direction, but I've never worked with raw sql before. I might wait and see if there are any other ways I can do it more easily through the query window before I try and figure yours out. Thanks
Sep 24 '07 #3
FishVal
2,653 Expert 2GB
Thanks, I'm sure that will point me in the right direction, but I've never worked with raw sql before. I might wait and see if there are any other ways I can do it more easily through the query window before I try and figure yours out. Thanks
"Raw SQL" and query window is just the same. You can switch from "Design view" to "SQL view" to represent the same DB action via visual interface or via SQL expression.

Kind regards,
Fish
Sep 24 '07 #4
Okay, but I'm unsure of how to apply this to my situation.

Compare these two queries:
first one for Jan-Dec year

Code: ( sql )
Expand|Select|Wrap|Line Numbers
  1. SELECT * FROM tblTable WHERE Year([dteDate])=[Your year input];
second one for Mar-Apr year

Code: ( sql )
Expand|Select|Wrap|Line Numbers
  1. SELECT * FROM tblTable WHERE Year(DateAdd("m", -3, [dteDate]))=[Your year input];
Right now in my SQL view I have:

SELECT TOP 100 defectsbyday.Date, Sum(defectsbyday.SumOfdetotal) AS YTDdetot, Sum(defectsbyday.SumOffetotal) AS YTDfetot, Sum(defectsbyday.SumOffrtotal) AS YTDfrtot, Sum(defectsbyday.SumOfpetotal) AS YTDpetot
FROM productionbyday INNER JOIN defectsbyday ON productionbyday.Date = defectsbyday.Date
GROUP BY defectsbyday.Date
ORDER BY defectsbyday.Date DESC;


So where will I add the

Expand|Select|Wrap|Line Numbers
  1.  SELECT * FROM tblTable WHERE Year(DateAdd("m", -3, [dteDate]))=[Your year input];
string into my SQL? Or can this be entered in the criteria somehow?
Sep 24 '07 #5
FishVal,

I figured it out, thanks! I just put that Year(DateAdd("m", -10, Date())) into the function now it works as advertised.

Thanks again

Craig
Sep 24 '07 #6
FishVal
2,653 Expert 2GB
You are welcome.

Best regards,
Fish
Sep 24 '07 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Mary | last post by:
I am trying to develop a query which will determine the average costs using a rolling average of the past 12 months of data. In other words, if I entered the Ship Month of January and the Ship...
1
by: MissiMaths | last post by:
This isn't really an access question as I can write the code myself(I hope) but need to know how the start of the financial year is worked out. If someone knows the rules or an algorithm, I would...
3
by: haydn_llewellyn | last post by:
Hi, My company runs on a fiscal calendar that starts on the first monday in July, and is based on a 13 week quarter (4 weeks, 4 weeks, 5 weeks). What I need, is a way of relating Date() to the...
1
by: ajmera.puneet | last post by:
If I have Calendar Control on Asp.net page and I have a table for Fiscal years on sql server then, How can I check the dates from table to Calendar Control,so that I can format the Calendar...
2
by: Jimmy | last post by:
I'm writing a simple query to pick out only records with a specific year. My query has two columns, TheDate and Expr1: Year(). If I run this query I get a list of all the dates in one column and in...
1
by: rkohon | last post by:
Hello all, I am new to JavaScript and need some ideas, suggestions, or code snippets. I have a form which requires the end user to put in a date for required items. I need javascript function to...
4
by: Twobridge | last post by:
Hi I am trying to perform a search that will return records based on a fiscal year search of the bill_Date. The user gives the year then I want to search based on the fiscal year (July 1 - June...
7
by: uzairahm | last post by:
Hi! I wanted to modify the query the query is given below. SELECT Format(,"yyyy") AS , ProcFees.ProcName, Count(ProcFees.ProcName) AS CountOfProcName FROM ProcFees INNER JOIN (Procedures INNER...
2
by: RZ15 | last post by:
Hi guys, I'm really drawing a blank here for how to deal with fiscal months in my monthly sales/receipts reports. My issue is that calculating the months is not as simple as saying 'if the invoice...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.