Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Crosstab Query Columns Sum

Posted on 2008-06-25
4
Medium Priority
?
1,742 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 2000 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

Ransomware: The New Cyber Threat & How to Stop It

This infographic explains ransomware, type of malware that blocks access to your files or your systems and holds them hostage until a ransom is paid. It also examines the different types of ransomware and explains what you can do to thwart this sinister online threat.  

Question has a verified solution.

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

Did you know that more than 4 billion data records have been recorded as lost or stolen since 2013? It was a staggering number brought to our attention during last week’s ManageEngine webinar, where attendees received a comprehensive look at the ma…
This article describes a method of delivering Word templates for use in merging Access data to Word documents, that requires no computer knowledge on the part of the recipient -- the templates are saved in table fields, and are extracted and install…
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…
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.

722 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