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()>Date Serial(Year(Dat e()),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?
6 6294
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
FishVal 2,653
Recognized Expert Specialist
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
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 ) - SELECT * FROM tblTable WHERE Year([dteDate])=[Your year input];
second one for Mar-Apr year
Code: ( sql ) - SELECT * FROM tblTable WHERE Year(DateAdd("m", -3, [dteDate]))=[Your year input];
Right now in my SQL view I have:
SELECT TOP 100 defectsbyday.Da te, Sum(defectsbyda y.SumOfdetotal) AS YTDdetot, Sum(defectsbyda y.SumOffetotal) AS YTDfetot, Sum(defectsbyda y.SumOffrtotal) AS YTDfrtot, Sum(defectsbyda y.SumOfpetotal) AS YTDpetot
FROM productionbyday INNER JOIN defectsbyday ON productionbyday .Date = defectsbyday.Da te
GROUP BY defectsbyday.Da te
ORDER BY defectsbyday.Da te DESC;
So where will I add the - 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?
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
FishVal 2,653
Recognized Expert Specialist
You are welcome.
Best regards,
Fish
Sign in to post your reply or Sign up for a free account.
Similar topics |
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 Year of
2004, I would want that month plus the preceding 11 months of data to
determine an average cost.
How can that criteria be entered in a query so that each month I can
get the most current 12 months of data to determine the average costs?
...
|
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 be most
grateful.
In 2001, when the 1st April 2004 was on a sunday, the first (monday to
friday) week of the financial year was the 9th to 13th April.
In 2002, the 1st was on a monday and the first week was 8th to 12th
april.
In 2003, the 1st...
|
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 actual fiscal month
(e.g. today is 01/07/05, and is the last day in June in our fiscal
calendar).
I tried many methods, and had hoped that DatePart() with the 'ww' flag
and DatePart() with the 'w' flag (to choose the first monday in July,
|
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 control cells according to my need.
I want to change the color of Dates according to fiscal month. i.e. As
Calendar control has dates for Current + next + Previous months, I need
to change the color of dates of month which is comes under Fiscal...
|
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 the second the year
from that date. All of these years are either 2005 or 2006. If I add
Year(2005) to the criteria of the second column I don't get any records.
Same for Year("2005"), Year('2005') and Year(#2005#). What gives? How am I
supposed...
| |
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 run on this date supplied by end user and for it to populate another area of the form with the Fiscal Year that this will be needed in.
Example: User populates form field with 25-SEPT-07 we need the the Quarter required to immediately poplate...
|
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 30) for the year
given. The table looks like this
Bill Table
id_Num bill_date bill_amount
23 7/1/2005 500.00
|
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 JOIN ProcDetails ON Procedures. = ProcDetails.) ON ProcFees. = ProcDetails.
WHERE ProcFees.ProcName<>"General Anaesthetic" And ProcFees.ProcName<>"Local Anaesthetic"
GROUP BY Format(,"yyyy"), ProcFees.ProcName
HAVING ((Format(,"yyyy")<>"IsNull")...
|
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 date is january then sum sales' because the first period may include the end of december or even the beginning of february and not all of january.
To help me with my problem, it's probably helpful to not think of it as fiscal months but think of...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |