Question : Access Query Error: specified expression as part of an aggregate function

I'm getting the following message when trying to run a query.  Can anyone tell me what the problem might be?

You tried to execute a query that does not include the specified expression 'Photagraphers Name' as part of an aggregate function.

Background:
I have a query that links two tables (checksNotPaid and Photographers) by Photographers Name.  The query worked fine until I added the following: "WageAdjust2: IIf([Event]="HOBNO",1.33,[WageAdjust])" on a new field

Answer : Access Query Error: specified expression as part of an aggregate function

> I hate when I can't figure out why something didn't work

Look at this query:

SELECT ProductID, Sum(UnitsInStock * UnitPrice) As TotValue
FROM Products
GROUP BY ProductID

The first row is the fields in your grid (two fields), the last is the "total" row. You will group by product and sum the expression. You tried something like this:

SELECT
 ProductID,
 IIf(Discontinued, UnitPrice/2, UnitPrice) as Adjusted,
 Sum(UnitsInStock * UnitPrice) As TotValue
FROM Products
GROUP BY ProductID

It doesn't matter whether you try to use 'Adjusted' in the expression or not. The query can no longer work.

Jet needs to know how to handle 'Adjusted'. Do you want to GROUP BY this expression? or do you want to perform an aggregation? You have only three ways out:

1) Grouping

SELECT
 ProductID,
 IIf(Discontinued, UnitPrice/2, UnitPrice) as Adjusted,
 Sum(UnitsInStock * UnitPrice) As TotValue
FROM Products
GROUP BY ProductID, IIf(Discontinued, Price/2, Price)

But that isn't what you want: you no longer have one total per product. Every difference in 'Adjusted' creates a new row.

2) Aggregating

SELECT
 ProductID,
 Avg(IIf(Discontinued, UnitPrice/2, UnitPrice)) as Adjusted,
 Sum(UnitsInStock * UnitPrice) As TotValue
FROM Products
GROUP BY ProductID

This works, but again isn't what you want. This shows an average price (or a total of prices, the minimum, the maximum), unusable in any further calculations...

3) Encapsulate

SELECT
 ProductID,
 Sum(UnitsInStock * IIf(Discontinued, UnitPrice/2, UnitPrice)) As TotValue
FROM Products
GROUP BY ProductID


Does that make sense?
(°v°)
Random Solutions  
 
programming4us programming4us