Solved

Crosstab Query Columns Sum

Posted on 2008-06-25
4
1,708 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
  • 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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Dot leaders between two labels in report 10 31
TSQL Challenge... 7 35
how to format one of my field to percent with precision of two? 3 17
RAISERROR WITH NOWAIT 2 14
Confronted with some SQL you don't know can be a daunting task. It can be even more daunting if that SQL carries some of the old secret codes used in the Ye Olde query syntax, such as: (+)     as used in Oracle;     *=     =*    as used in Sybase …
A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…

791 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