473,385 Members | 1,192 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Crosstab Query Adding Pivoted Columns

Hi,

If I have a cross tab query which counts an [id number] and pivots on a [status] for a [course], how do I add a new row heading that will sum only a certain few status's. E.g. The [status] field has "A", "B", "C", "D". I want to add a row heading that is the sum of [id numbers] under "A" and "D"?

Thanks
Mar 19 '09 #1
5 2542
Stewart Ross
2,545 Expert Mod 2GB
Hi. If you want to show only the "A" and "D" columns in your crosstab list you need to restrict the rows to those where the status is in your 'required list' of "A" and "D". To do so in a crosstab query, follow these steps:

1. add another copy of your Status field into the query editor grid
2. change the default type in the Total row for that field from Group By to Where
3. in the Criteria row for that field add In ("A", "D")
4. save the query and run it

If you really mean that you want to keep the crosstab headers for A, B, C and D as they are and show a separate row heading which is the total for A and D only then forget the WHERE clause - you won't need it. Instead, add a calculated field as a row heading containing an expression such as the following:

AD Total: Sum(IIF([status] In ("A", "D"), 1, 0))

Make sure you change the Group By status for this field to Expression as otherwise you will receive an error telling you that you can't use an aggregate function in a group by.

-Stewart
Mar 19 '09 #2
Brilliant. The second one was what I was after. I had started to create new select queries with the original cross tab. I made an expression in there to add up the fields I needed as an expression. This reduces my ever growing mountain of queries I'm amassing, and is much cleaner.

Cheers
Mar 19 '09 #3
Could you explain how this works:

AD Total: Sum(IIF([status] In ("A", "D"), 1, 0))

Does it count 1 for every occurance of A or D, is that right?
Mar 19 '09 #4
This is now my working query:

Expand|Select|Wrap|Line Numbers
  1. TRANSFORM CLng(Nz(Count([DIR__ID]),0)) AS N
  2. SELECT   [Direct_Applications_2009 Query].DIR_AOS_CODE, 
  3.          [Direct_Applications_2009 Query].DIR_AOS_DESC, 
  4.          [Direct_Applications_2009 Query].UG_PG, 
  5.          [Direct_Applications_2009 Query].FULL_PART, 
  6.          Count([Direct_Applications_2009 Query].DIR__ID) AS [Total Of DIR__ID], 
  7.          Sum(IIf([DIR_STAGE_CODE] In ("DIRCD","DIRCF","DIRCO","DIRUD","DIRUF","DIRUO"),1,0)) AS Offers
  8. FROM     [Direct_Applications_2009 Query]
  9. GROUP BY [Direct_Applications_2009 Query].DIR_AOS_CODE, 
  10.          [Direct_Applications_2009 Query].DIR_AOS_DESC, 
  11.          [Direct_Applications_2009 Query].UG_PG, 
  12.          [Direct_Applications_2009 Query].FULL_PART
  13. ORDER BY [Direct_Applications_2009 Query].UG_PG DESC 
  14. PIVOT    [Direct_Applications_2009 Query].DIR_STAGE_CODE In
  15.          ("APP","DIRUF","DIRUO","DIRCF","DIRCO","DIRUD","DIRCD","DIRCA","DIRRJ","DIRW","DIRDEF");
Thankyou again
Mar 19 '09 #5
Stewart Ross
2,545 Expert Mod 2GB
@Mysterydave
That is correct; the IIF simply tests to see if the [status] field is an "A" or a "D", returns 1 if it is and 0 if it isn't. Sum then totals the value returned - which will be the same as a count of the number of rows that contain an A or a D status at the level of the grouping involved in the crosstab.

Glad you have adapted it to work for your particular query!

-Stewart
Mar 19 '09 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

8
by: Donna Sabol | last post by:
First, I should start by saying I am creating a database to be used by some very impatient, non-computer literate people. It needs to be seameless in it's operation from their point of view. I...
1
by: Nathan Bloomfield | last post by:
Does anyone know if there is any documentation which relates to Access2k + ? or can anyone help adjust the code? I am having trouble converting the DAO references. TITLE :INF: How to...
4
by: No Spam | last post by:
Dear Access 2000 users, I have a crosstab query that puts together certain information perfectly. It has a criteria that is based on a form that limits how many columns are returned based on...
0
by: Richard Hollenbeck | last post by:
I have a crosstab query that shows all the scores of all the activities of all the students in all courses, with the students being in the rows and the activities being in the columns and the...
2
by: scott.k.fraley | last post by:
....and the SELECT thats trying to pull from said Query doesn't like it one bit! ;) I'm working on this project (in Access 2002) and there is a report who's RecordSource is the following...
8
by: Penny | last post by:
(Access 2003 Multiuser Split DB, Windows XP Pro) Hi All, I would really appreciate just some basic tips on how to make a Crosstab Form based on a Crosstab Query. The query always has the same...
13
by: salad | last post by:
Operating in A97. I didn't receive much of a response conserning Pivot tables in Access. Pivot tables are nice, but a CrossTab will work for me too. Using a Pivot table, one is actually...
4
by: m.wanstall | last post by:
I have a crosstab query that compiles data for Months of the year. I have a stacked select query on top of that crosstab query that uses the latest 2 months data and exports it to a fixed length...
4
by: mattlightbourn | last post by:
Hi all, I have a problem which has been driving me nuts. Crosstab queries! I have a database witch a few different tables to do with garment manufacturing. I have a table for a client...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.