Solved

Aggregate Function error

Posted on 2016-10-09
7
40 Views
Last Modified: 2016-10-10
Experts, I am trying to add the below to a query and after doing so I get an error: "YOu tried to execute a query that does not include the specified expression 'Amount' as part of an aggregate function.

AccrueUSDEquiv: Sum(IIf([CurrencyID]=1,Nz([TAccrueMoINLocalCurr],0),Nz(([TAccrueMoINLocalCurr]*[ExchangeRate]),0)))

Why do I get this error?  The query works fine until I try to add this.
0
Comment
Question by:pdvsa
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
7 Comments
 

Author Comment

by:pdvsa
ID: 41835927
here is the query:

its big
SELECT
tblDraws_Details1.Amount, tblDraws_Details1.ValueDate, tblRepayment.Amount, tblRepayment.Currency, tblRepayment.ValueDate, tblRepayment.PaymentMadeYN, (DSum("Amount","tblDraws_Details1","ID = " & [DrawIDrpmt])+Nz(DSum("Amount","tblRePayment","DrawIDrpmt = " & [DrawIDrpmt] & " and PaymentMadeYN = 'Yes' "),0)) AS Balance, Sum(IIf([CurrencyID]=1,Nz([TAccrueMoINLocalCurr],0),Nz(([TAccrueMoINLocalCurr]*[ExchangeRate]),0))) AS AccrueUSDEquiv, Format([tblRepayment].[ValueDate],"mmmm") AS CurrentMonthToAccrue, ([Balance])*([SiborRate]+[Margin])*([DayCountToMaturity]/360) AS TInterestToMatLocalCur, ([tblRepayment].[ValueDate])-([tblDraws_Details1].[ValueDate]) AS DayCountToMaturity, DLookUp("[MarginRate]","tblInterest_Margin","[FacID]= " & [tblRepayment].[ID_Facility]) AS Margin, tblInterest_Sibor.SiborRate, ([Balance])*([SiborRate]+[Margin])*([DaysToAccrueCurMo]/360) AS [TAccrueCurrMo(InLocalCurr)], tblCurrencyExchange.CurrencyName, [tblRepayment].[ValueDate]-dhFirstDayInMonth([tblRepayment].[valuedate])+1 AS DaysToAccrueCurMo, tblRepayment.Comments
FROM
tblDraws_Details1 INNER JOIN ((tblRepayment LEFT JOIN tblInterest_Sibor ON tblRepayment.ID = tblInterest_Sibor.RpmtID) LEFT JOIN tblCurrencyExchange ON tblRepayment.Currency = tblCurrencyExchange.CurrencyID) ON tblDraws_Details1.ID = tblRepayment.DrawIDrpmt
WHERE
(((Format([tblRepayment].[ValueDate],"mmmm"))=Format(Date(),"mmmm")) AND ((tblDraws_Details1.ID_facility)=15))
ORDER BY
tblDraws_Details1.ID;
0
 
LVL 20
ID: 41835939
in order to use SUM, you must use an aggregate function on the rest of the columns such as GROUP BY

optionally, if you don't want to do that, you can use DSUM which needs the fieldname (or expression), table or query name, and conditions for matching
0
 

Author Comment

by:pdvsa
ID: 41835945
Hi Crystal,

thank you.  I didnt know I could do that.  I would like to use the Dsum method.  
I simply changed Sum to Dsum and i get a wrong number of arguments error.  
I am sure there is more to it than simply doing what i did.  

what should I do now?  grateful for your help.
0
Back Up Your Microsoft Windows Server®

Back up all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

 
LVL 47

Accepted Solution

by:
Dale Fye (Access MVP) earned 250 total points
ID: 41836025
Yes, but using domain functions in a query is generally considered to be a bad practice.  They are slow to execute, and because the query optimizer cannot use them, the query it generally poorly optimized as well.

I would recommend that you either write correlated sub-queries to get your sums, or write aggregate sub-queries and join them to the other tables in the query.
0
 
LVL 20

Assisted Solution

by:crystal (strive4peace) - Microsoft MVP, Access
crystal (strive4peace) - Microsoft MVP, Access earned 250 total points
ID: 41836036
you're welcome

as Dale suggested, a subquery might be better.  You can also make another query and join it in.

the problem using SUM is that you then must apply an aggregate to every column, which is not happening

> "domain functions in a query is generally considered to be a bad practice.  They are slow to execute"
on indexed fields, they actually perform quite well

> "wrong number of arguments error."
post your SQL.  You can also try a subquery ...
0
 

Author Closing Comment

by:pdvsa
ID: 41836331
Thank you very much.  I will work on crafting something.  Step by step.  

Have a good night
0
 
LVL 20
ID: 41836927
you're welcome ~ happy to help
0

Featured Post

Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Why this Update SQL not Updating! 15 57
Fields don't match on a query 9 46
Access Database 2007 - automating reports being sent by email 2 57
Access Query function 4 51
I see at least one EE question a week that pertains to using temporary tables in MS Access.  But surprisingly, I was unable to find a single article devoted solely to this topic. I don’t intend to describe all of the uses of temporary tables in t…
A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

739 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question