473,396 Members | 2,024 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,396 software developers and data experts.

Subquery to Calculate Year To Date Amount?

30
Hi I am trying to calculate the YTD amount and I keep getting the following error "You tried to execute a query that does note include the specified expression 'Fiscal Year' as part of an aggregate function". Can you offer any assistance?

Expand|Select|Wrap|Line Numbers
  1. SELECT GetFiscalYear([InvoiceDate]) AS [Fiscal Year], fFiscalPeriod([InvoiceDate]) AS Period, BudgetCodeID, Sum(InvoiceDetails.Amount) AS SumOfAmount, 
  2. (SELECT Sum(InvoiceDetails.amount) AS YTD                                 
  3.    FROM Invoices AS Inv INNER JOIN InvoiceDetails AS InvD ON Inv.InvoiceID = InvD.InvoiceID    
  4.    WHERE Inv.InvoiceDate >= DateSerial(Year([Invoices].[InvoiceDate]),1,1)                
  5.      AND Inv.InvoiceDate < DateSerial(Year([Invoices].[InvoiceDate]),                     
  6.        Month([Invoices].[InvoiceDate]) + 1, 1)) AS YTDAmount 
  7. FROM Invoices INNER JOIN InvoiceDetails ON Invoices.InvoiceID = InvoiceDetails.InvoiceID 
  8. GROUP BY GetFiscalYear([InvoiceDate]), fFiscalPeriod([InvoiceDate]), InvoiceDetails.BudgetCodeID; 
  9.  
Aug 2 '10 #1
2 2079
Jerry Winston
145 Expert 100+
Your GROUP BY statement literally does not include the alias [Fiscal Year].

Remove the AS [Fiscal Year] part and see if there are any other errors.
Aug 27 '10 #2
NeoPa
32,556 Expert Mod 16PB
Hi Jerry. Nice to see you visiting Access :)

I'd be surprised if the ALIAS had any effect in Jet SQL. It normally ignores the ALIAS and doesn't even allow GROUPing BY it. What may be an issue here is that it's a function call. I can't see how exactly, as normally a function which includes a record-level parameter - one of the fields - generally gets run for each record. A function which has no relative parameter will typically be optimised such that it's only called at the start and the result simply reused (EG when desiring a random value, it needs to be passed a field reference to force it to run for each record - otherwise the same, single, random value is returned each record).

It may still be worth losing the ALIAS just to test, but I expect it doesn't like running the function in both the SELECT and GROUP BY clauses.
Aug 27 '10 #3

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

Similar topics

4
by: Manny Chohan | last post by:
Hi Can anyone tell me how i can calculate yesterday date using asp? Thanks manny
1
by: David | last post by:
Can someone help me with this. I need to calculate the week ending date of the first week of the year based upon a year provided by the user. Is there a simpler way other than writing my own...
2
by: ltamisin | last post by:
Hi Im working on a Year(Date) function right now, the output of that function is this "2005", my question is how can i change the format into this "05" Function: Year(Date) Output: 2005...
1
by: turtle | last post by:
I am calculating actual costs against a budget and have stumbled upon a problem. For estimating each months hours i have setup text fields for our Program Managers(PM) to put in approximate hours...
11
by: Laery | last post by:
Hi, I'm currently adding a new module to an old borland C3.1 application (dos). And I need to calculate a date by subtracting the number of days from a given date. I know I could use an...
8
by: Tim | last post by:
Does anyone know how to convert a date to the hundred year date format. For example, how would i convert 8/11/2004 to its hundred year date format. Thanks! Tim
2
by: Amanda | last post by:
This is hotel reservation when a departure date is changed manually by user input ( to a valid date in date format - validity is checkedsomewhere else), the arrival date is set to the previous date...
1
by: Jimmy | last post by:
I'm trying to run a query that will show only records where the year in a date field equals the current year: SELECT tblSideJob.SideJobID, tblSideJob.Date FROM tblSideJob WHERE...
3
by: fatmir | last post by:
i wont to calculate the date for example: 22.09.1999 today:02.07.2007 -------------------------- day.month.year(day.month.8 year) please help me
2
by: shimul | last post by:
Hi All, If I set up a form with start date (choose from calendar) and end date. Each week Start date (Monday ) and want to automatically calculate end date (sunday each week) . how can I...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
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,...
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
jinu1996
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...
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.