Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Grouped weighted average

Status
Not open for further replies.

mas0212

Programmer
Jan 16, 2007
2
US
Hello,

I'm trying to do a grouped weighted average query and am not having much luck.

I have the following sub-query defined as [Mike - Total Floating Balance by Deal Number]:

[tt] SELECT Order.[Deal Number],
Sum(IIf(Order.[Fixed/Float]="Fixed",0,Order.[QTY MM]*Issue.[Factor])) AS [Total Floating Balance]
FROM Issue
INNER JOIN [Order]
ON Issue.Cusip=Order.OCusip
GROUP BY Order.[Deal Number]
HAVING Order.[Deal Number]<>"";
[/tt]

Then I have this query that attempts to use the subquery above:

[tt] SELECT O.[Deal Number],
Sum(O.[QTY MM]) AS [Notional Balance],
Sum(O.[QTY MM]*I.[Factor]) AS [Current Balance],
Sum(IIf(O.[Fixed/Float]="Floating",O.[QTY MM]*I.[Factor],0)) AS [Floating Balance],
Sum(IIf([Floating Balance]=0,0,IIf(I.[Fixed/Float]="Floating",O.[QTY MM]*I.[Factor],0)*O.[Spread/DM])/T.[Total Floating Balance]) AS [Current DM]
FROM Issue AS I
INNER JOIN (
[Order] AS O
INNER JOIN [Mike - Total Floating Balance by Deal Number] AS T
ON O.[Deal Number] = T.[Deal Number])
ON I.Cusip = O.OCusip
GROUP BY O.[Deal Number],
T.[Total Floating Balance];
[/tt]

This query gives me the following error:

[tt]Subqueries cannot be used in the expression: (IIf([Floating Balance]=0,0,IIf([Fixed/Float]="Floating",[QTY MM]*[Factor],0)*[Spread/DM])/T.[Total Floating Balance])[/tt]

Any suggestions as to where I'm going wrong, or whether this can actually be done?

Thanks very much.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top