Solved

Crosstab Query Columns Sum

Posted on 2008-06-25
4
1,680 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

Get up to 2TB FREE CLOUD per backup license!

An exclusive Black Friday offer just for Expert Exchange audience! Buy any of our top-rated backup solutions & get up to 2TB free cloud per system! Perform local & cloud backup in the same step, and restore instantly—anytime, anywhere. Grab this deal now before it disappears!

Join & Write a Comment

PL/SQL can be a very powerful tool for working directly with database tables. Being able to loop will allow you to perform more complex operations, but can be a little tricky to write correctly. This article will provide examples of basic loops alon…
Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
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…

762 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

12 Experts available now in Live!

Get 1:1 Help Now