Example: Crosstab Query - Count with row totals

To distribute camp t-shirts on the first day of a summer day camp you need a stack of t-shirts for each unit. How many of each size do you need for each unit of campers? In this example, (based on a real day camp) there are 12 units, 4 sizes for Adult-sized t-shirts and 4 sizes for Child-sized t-shirts. This could be messy! A crosstab datasheet is a very useful way to display this information.

Rows: The combinations of unit and t-shirt type (Adult or Child sizing) are listed down the left (row headings). Each unit needs at least 2 rows, one for the Adult sizes and one for Child sizes. A third row appears if there is a record that does not list a t-shirt size.

Columns: The sizes are across the top (column headings). The column <> is for records that do not have a value for the t-shirt size. (Whoops!) This crosstab query also includes a Total for each row, Total Of ID. Very useful when counting out the stacks.

The sizes across the top and the units down the side are in alphabetical order. To sort columns in order by increasing or decreasing size we would need another table that ordered these sizes and set up a relationship.

Cells: The value in a cell is the Count of t-shirts needed of that size (column) for that t-shirt type (row) and camp unit (row).

Results of Crosstab query

 Icon: Mouse click Click the image to see labels

Examine the 3 rows for the unit J1. This unit needs both Adult size t-shirts and Child sizes. One record in J1 does not have a t-shirt size entered (Column <>).

A total of 8 adult (A) shirts (Total Of ID): 
   2 medium (M)
   3 small (S)
   3 extra large (X)
A total of 8 child (C) t-shirts (Total Of ID)::
   5 large (L)
   2 medium (M)
   1 extra large (X).

Crosstab Query Wizard

Access tries to make creating a crosstab query easy. The wizard walks you through the choices that you must make. You must pick one or more fields for row headings and one field for column headings. You must pick a field to use for the value in the cell, which is a calculation like a SUM or COUNT.

Let's look at the steps to create the T-shirts_Crosstab query shown above.

Dialog: New Query - Crosstab Query WizardButton: New Object - QueryYou start the Crosstab Query Wizard from the New Objects button:
   New Objects button | Query | Crosstab Query Wizard
 

Dialog: Crosstab Wizard

Icon: Mouse click View each step of the wizard:
1  2  3  4  5 
 

Step 1: Pick source for data: Table: Day Camp Campers & Staff
The bottom portion of the dialog will change as you make choices.

Step 2: Pick fields to use a row headings. You can use more than one.

Step 3: Pick field to use for column headings. Only 1.

Step 4: Pick value to show in cells. There is a checkbox for including a sum of each row.

Step 5: Pick a name for the query.


Design View of the query:

Query Design View: CrosstabThe design view of the query shows that it is a Totals query, with a new row in the grid, Crosstab. The choices for this row are Row Heading, Column Heading, Value, and (not shown).
 


Lessons Databases Appendix




Teachers: Request permission to use this site with your class
 
Copyright © 1997-2012 Jan Smith   <jegs1@jegsworks.com>
All Rights Reserved

Icon: DonwloadIcon: CDWant a local copy with no ads? - Download/CD

Want to help?


~~  1 Cor. 10:31 ...whatever you do, do it all for the glory of God.  ~~


Last updated: 30 Apr 2012