Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Add Totals row to crostab query in Access

Posted on 2010-11-15
6
Medium Priority
?
1,011 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
 [eBook] Windows Nano Server

Download this FREE eBook and learn all you need to get started with Windows Nano Server, including deployment options, remote management
and troubleshooting tips and tricks

 
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

If you need a simple but flexible process for maintaining an audit trail of who created, edited, or deleted data from a table, or multiple tables, and you can do all of your work from within a form, this simple Audit Log will work for you.
With its various features, Office 365 can not only help you with your day-to-day business tasks, it can also do wonders for your marketing campaign.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…

618 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