Solved

Crosstab Query Columns Sum

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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Suggested Solutions

The first two articles in this short series — Using a Criteria Form to Filter Records (http://www.experts-exchange.com/A_6069.html) and Building a Custom Filter (http://www.experts-exchange.com/A_6070.html) — discuss in some detail how a form can be…
I'm trying, I really am. But I've seen so many wrong approaches involving date(time) boundaries I despair about my inability to explain it. I've seen quite a few recently that define a non-leap year as 364 days, or 366 days and the list goes on. …
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…

920 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

15 Experts available now in Live!

Get 1:1 Help Now