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!

Tough Query Question

Status
Not open for further replies.

tma12000

IS-IT--Management
Nov 24, 2003
19
US
I am trying to create a output field in a query that takes the sume of a field called "spend" and divides it by the count that same field, thus giving me an average. Here is the code Ive tried that has not worked:

Avg Monthly Spend: (Sum([Expense Amount]))\(Count([Expense Amount]))

I get an "You cannot have aggragate functions in a group by clause"

Any thoughts,
Thanks,
Tim
 
This may seem overly simple, but couldn't you just get rid of the sum and count and just use avg?

Like this
SELECT Avg([expense amount]) AS expense_amount FROM Your_Table;

ChaZ
 
Heh heh thanks Chaz, I thought about that.Unfortuanley I am looking at expense line item data so I have several lines per person per month. When I put the date filter on (to just look at Jan for instance) it outputs every expense list for that month and thus gives me an avg per line item. So I need to 1st do a count on the month, then a sum then do the math.

Thanks,
Tim
 
To add...the expense date format is dd/mm/yy... Is there an easy way to remove the day from that format. This is the crux of my problem.
 
Ok, this may help

get rid of the date, and use the following

Format ([Date], "YYYY-MM")

This will give you the year first, then the month.

So 1/15/03 will be 0003-01.

I like to use the four digit year, and put it before month, because if you ever need to sort, this will be sortable.

Hope it helps.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top