Solved

Crosstab Query Columns Sum

Posted on 2008-06-25
4
1,731 Views
Last Modified: 2013-11-29
Is there an easy way to sum the columns in a cross-tab query?
0
Comment
Question by:Michael2008
[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
  • 2
4 Comments
 
LVL 77

Accepted Solution

by:
peter57r earned 500 total points
ID: 21881372
No.

To do it you need to create two further queries.  I'll assume your current query is Crosstab1
First create a copy of Crosstab1 as Crosstab2.
Modify Crosstab2 to change the fieldname in the RowHeading GroupBy column (probably the first column in the grid)  to a fixed value which will sort after all real values in the data (Such as ZZZ or 999999).
This will create a crosstab with just one row which contains the totals of each column.

Create a union query:

Select * from crosstab1
union all
select * from crosstab2

That will give you a result which shows the column totals.
0
 
LVL 16

Expert Comment

by:Rick_Rickards
ID: 21885810
If I undrstand you right you're trying to get a running sum of all the columns in your cross tab query.  For example, if you broke the years sales down by months, Group By Year (Row Heading), Month 9 (Column Heading) and Sum of Sales (Value) all you need do to add a sum of Total sales for the year is add a Rowyeading that is the Sum of Sales.

If this is unclear, post your cross Tab query and I'll provide the syntax.
0
 

Author Comment

by:Michael2008
ID: 21958671
Sorry that I was so slow on the acceptance, but I was on vacation and didn't have internet access.  Thanks for the help, and sorry again for the wait.
0
 
LVL 16

Expert Comment

by:Rick_Rickards
ID: 21960245
Hate to spoil the fun but I believe the answer was Yes and No, (It really depends).  In the cases of YES then Yes the columns of a cross tab query can be easily summed within the query itself providing it's own column as a sum of all of the other columns broken down by the Cross Tab Query itself.

In cases where a Cross Tab query the creates is column headers from a clause like Sum or Count can be made to provide a RowHeader that is the sum of all of those columns.  Even expression, (in certain ceases), can apply as well.

Other column headers derived from clauses like Max, stDevm, Var, First, Last can not without the help of a Sub Query or secondary Query.  Expression on the other hand remains a maybe yes, maybe no it depends on the expression.

Sorry if this was previously unclear, I'd hoped to see the SQL of the Cross Tab Query in question which would have made it much easier to say yes or no and avail a new version that did the column sum as desired if it was possible in this case.



0

Featured Post

Do you have a plan for Continuity?

It's inevitable. People leave organizations creating a gap in your service. That's where Percona comes in.

See how Pepper.com relies on Percona to:
-Manage their database
-Guarantee data safety and protection
-Provide database expertise that is available for any situation

Question has a verified solution.

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

This article describes two methods for creating a combo box that can be used to add new items to the row source -- one for simple lookup tables, and one for a more complex row source where the new item needs data for several fields.
You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

636 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