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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Crosstab query -- average of the transformed field

Status
Not open for further replies.

dkaplan

Programmer
Jan 29, 2001
98
US
I have a crosstab query that returns averages by month.
I want to add a final column that contains the average of the averages. (I know that this is not generally a sound practice, but there is a reason)
The current output looks like

action_type, worker_type april may june
initial lead 10 20 30

I'd like it to look like

action_type, worker_type april may june Avg
initial lead 10 20 30 20

The issue I've hit is that I cannot simpy use ([april] + [may] + [june])/3 to get the averages because the names of the months will change every quarter. (There is an inner query that groups on month)

My current code is below


PARAMETERS [Enter start date] DateTime, [Enter end date] DateTime;
TRANSFORM Round(Avg([MainUnionQuery].[Expr1]),2) AS [Avg]
SELECT ActionType, WorkerType
FROM MainUnionQuery
GROUP BY ActionType, WorkerType
PIVOT MainUnionQuery.Month;
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top