MTD and YTD query Error 3122

josros60

Well-known Member
Joined
Jun 27, 2010
Messages
786
Office Version
  1. 365
When i run a query I get error 3122, you tried to execute a query that does not specified the expression "TransactionDate" as part of an aggregate function.

sql View:
Code:
SELECT Transactions.TransactionDate, Transactions.TransactionID, Transactions.EmployeeID, [Transactions Details].TransactionID, [Transactions Details].CodeID, [Transactions Details].Amount, CodesCategory.CodeCategoryID, [B][COLOR=red]Sum(Abs(Format([TransactionDate],"yyyymm")=Format(Date(),"yyyymm"))*[Amount]) AS MTDRev[/COLOR][/B]
FROM CodesCategory INNER JOIN ((Transactions INNER JOIN [Transactions Details] ON Transactions.TransactionID = [Transactions Details].TransactionID) INNER JOIN Codes ON [Transactions Details].CodeID = Codes.CodeID) ON CodesCategory.CodeCategoryID = Codes.CodeCategoryID
WHERE (((Transactions.TransactionDate)>=[forms]![ReportDateRange]![BeginDate] And (Transactions.TransactionDate)<=[forms]![ReportDateRange]![EndDate]));

Thank you
 

Excel Facts

Links? Where??
If Excel says you have links but you can't find them, go to Formulas, Name Manager. Look for old links to dead workbooks & delete.
I changed to expression by when i run it it shows "0" amount for field where there's an amount for march 2011.

here the new sql view after the changes:

Code:
SELECT Transactions.TransactionDate, Transactions.TransactionID, Transactions.EmployeeID, [Transactions Details].TransactionID, [Transactions Details].CodeID, [Transactions Details].Amount, CodesCategory.CodeCategoryID, Sum(Abs(Format([TransactionDate],"yyyymm")=Format(Date(),"yyyymm"))*[Amount]) AS MTDRev
FROM CodesCategory INNER JOIN ((Transactions INNER JOIN [Transactions Details] ON Transactions.TransactionID = [Transactions Details].TransactionID) INNER JOIN Codes ON [Transactions Details].CodeID = Codes.CodeID) ON CodesCategory.CodeCategoryID = Codes.CodeCategoryID
WHERE (((Transactions.TransactionDate)>=[forms]![ReportDateRange]![BeginDate] And (Transactions.TransactionDate)<=[forms]![ReportDateRange]![EndDate]));
This has been driving me crazy i have been trying different ways and never worked until this now at least i got not error but the fields is 0.

thank you again
 
Upvote 0
This is a tortuous expression anyway:
Code:
Sum(Abs(Format([TransactionDate],"yyyymm")=Format(Date(),"yyyymm"))*[Amount]) AS MTDRev

Your query already includes a date parameter:
Code:
WHERE 
	(
		(
		(Transactions.TransactionDate)>=[forms]![ReportDateRange]![BeginDate] 
		And 
		(Transactions.TransactionDate)<=[forms]![ReportDateRange]![EndDate]
		)
	)

Why isn't that enough?
 
Upvote 0

Forum statistics

Threads
1,224,521
Messages
6,179,275
Members
452,902
Latest member
Knuddeluff

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top