Link to home
Start Free TrialLog in
Avatar of pdvsa
pdvsaFlag for United States of America

asked on

Aggregate Function error

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.
Avatar of pdvsa
pdvsa
Flag of United States of America image

ASKER

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;
Avatar of crystal (strive4peace) - Microsoft MVP, Access
crystal (strive4peace) - Microsoft MVP, Access

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
Avatar of pdvsa

ASKER

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.
ASKER CERTIFIED SOLUTION
Avatar of Dale Fye
Dale Fye
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of pdvsa

ASKER

Thank you very much.  I will work on crafting something.  Step by step.  

Have a good night
you're welcome ~ happy to help