?
Solved

Add Totals row to crostab query in Access

Posted on 2010-11-15
6
Medium Priority
?
1,001 Views
Last Modified: 2012-05-10
Hi,

I use the following pivot query in Access database to track the daily work rate of 9 teams:

TRANSFORM Count(Master.Actual) AS Units
SELECT Master.Actual
FROM Teams INNER JOIN Master ON Teams.ID = Master.Teams_ID
WHERE (((Master.Actual) Is Not Null))
GROUP BY Master.Actual
PIVOT Teams.ID

This gives me the dataset in the attached picture..
 Datatable produced by the Query
I have spent way too long trying to add a row to the bottom of that dataset to show the totals..can anyone help / explain? (i am aware there is a totals button in Access 2007 but this is not the solution)

Thanks for reading
0
Comment
Question by:laserhalen
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 
LVL 8

Expert Comment

by:infolurk
ID: 34141472
The totals button is the one that should give you column totals. Are you not using 2007, or is it not giving the desired value?

For row totals, add the value field again as a row heading.
0
 

Author Comment

by:laserhalen
ID: 34141668
Yes im using 2007 and it is the column totals im looking for but the query is to support a chart, so i need to calculate the totals as part of the query..dont i?

Row totals i can get, what im looking for is to add a single row to the bottom that shows the total for each column..is this posible? i can generate this row on its own usint a different query (that searches the query i have posted) but then i couldn't add it to the table using UNION..

Thanks for the reply..
0
 
LVL 11

Accepted Solution

by:
LambertHeenan earned 2000 total points
ID: 34145861
You can use a union query.  

You have your crosstab query (Query-SC1) which returns the details, so then you just build a totals query that uses Query-SC1 as its source, summing all the relevant fields (1 through 9) with the first field in the quey being a simple 'calulated' field:  select distinct "Totals" as Total, sum(Query-SC1.1) as 1, etc. etc. and save that as SC1-Totals.

Then you can construct the union query

Select * from SC1 orderby Actual
Union select * from SC1-Totals

One very important caveat. Your cross tab must always return the same number of columns in order for the SC1-Totals and the Union query to work, so be sure to specify the column headings in the crosstab pivot clause...

TRANSFORM Count(Master.Actual) AS Units
SELECT Master.Actual
FROM Teams INNER JOIN Master ON Teams.ID = Master.Teams_ID
WHERE (((Master.Actual) Is Not Null))
GROUP BY Master.Actual
PIVOT Teams.ID In(1,2,3,4,5,6,7,8,9)

0
Office 365 Training for Admins - 7 Day Trial

Learn how to provision tenants, synchronize on-premise Active Directory, implement Single Sign-On, customize Office deployment, and protect your organization with eDiscovery and DLP policies.  Only from Platform Scholar.

 
LVL 11

Assisted Solution

by:LambertHeenan
LambertHeenan earned 2000 total points
ID: 34145880
P.S. Because the dates in column 1 have digits in them they will sort in front of the 'Totals' colum and so you get your result: totals at the bottom.
0
 

Author Comment

by:laserhalen
ID: 34168829
@ LambertHeenan
Excellent, thank you.
Took me a while to understand it..I thought you couldnt use DISTINCT in access?!

Anyway thanks again.
0
 
LVL 11

Expert Comment

by:LambertHeenan
ID: 34172732
Glad to help. And SQL without DISTINCT would be kind of restricted, don't you think? :-)
0

Featured Post

Moving data to the cloud? Find out if you’re ready

Before moving to the cloud, it is important to carefully define your db needs, plan for the migration & understand prod. environment. This wp explains how to define what you need from a cloud provider, plan for the migration & what putting a cloud solution into practice entails.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes how you can use Custom Document Properties to store settings and other information in your workbook so that they will be available the next time you open the workbook.
Code that checks the QuickBooks schema table for non-updateable fields and then disables those controls on a form so users don't try to update them.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
Suggested Courses

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question