Solved

Add Totals row to crostab query in Access

Posted on 2010-11-15
6
945 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
  • 3
  • 2
6 Comments
 
LVL 8

Expert Comment

by:infolurk
Comment Utility
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
Comment Utility
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 500 total points
Comment Utility
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
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 11

Assisted Solution

by:LambertHeenan
LambertHeenan earned 500 total points
Comment Utility
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
Comment Utility
@ 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
Comment Utility
Glad to help. And SQL without DISTINCT would be kind of restricted, don't you think? :-)
0

Featured Post

Backup Your Microsoft Windows Server®

Backup all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Join & Write a Comment

As with any other System Center product, the installation for the Authoring Tool can be quite a pain sometimes. This article serves to help you avoid making these mistakes and hopefully save you a ton of time on troubleshooting :)  Step 1: Make sur…
My experience with Windows 10 over a one year period and suggestions for smooth operation
Learn how to create and modify your own paragraph styles in Microsoft Word. This can be helpful when wanting to make consistently referenced styles throughout a document or template.
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…

772 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now