There are many ways that queries can help you summarize and analyze all that information in your database. A crosstab query displays summarized information in a table format that makes it easy to analyze and compare data. Look at the information displayed in Figure 6-25difficult to see the bottom line, isn't it? Now look what happens when the same information is placed in a crosstab query, as shown in Figure 6-26. Which do you think is easier to understand?
You can create a crosstab query in Design View or by using the Crosstab Query Wizard. The Crosstab Query Wizard is usually much easier, but it does have some limitations:
In this lesson you will use the Crosstab Query Wizard to create a query that summarizes monthly ticket sales by tours.
In the Database window, click the Queries icon in the Objects bar and click the New button.
The New Query dialog box appears.
Select Crosstab Query Wizard and click OK.
The first step of the Crosstab Query Wizard appears. Here you need to select the table or query that contains the values you want. For this exercise you will use the ToursByName query as the source for the crosstab query.
Click the Queries option in the View section to display the queries in the database, select the qryToursByName query, and click Next.
The second step of the Crosstab Query Wizard is which field you want to use as the row headings for the crosstab. Let's use the TourName field for your row headings.
Double-click the TourName field and click Next.
The next step is determining which field you want to use for your column headings. Let's use the Date field as the column heading.
Double-click the Date field.
Because you selected a date field, the asks by which interval you want to group the dates: date, month, quarter, year, or date/time. For this exercise you want the date column to group dates by months.
Double-click the Month option.
Probably the most important step in the Crosstab Query Wizard is determining which field you want to calculate where columns and rows intersect and the type of calculation you want to use to summarize the fields.
Select the Number of Tickets field from the Fields list and the Sum option from the Functions list, as shown in Figure 6-27.
This will calculate the total number of tickets sold for each tour, grouped by month.
You have to give your crosstab query a name.
Type qryTicketsByDate and click Finish.
Access saves the query with the name "qryTicketsByDate" and displays the results of the query, as shown in Figure 6-26. Let's modify the crosstab query and add some limiting criteria.
Click the View button to display the crosstab query in Design view.
The crosstab query appears in Design view as shown in Figure 6-28. Notice the Crosstab row, which you use to determine if a field should be a column heading, row heading, or value.
Double-click the First Class field in the qryToursByName list.
You only want to see tours for passengers without first class tickets.
Click the First Class column's Total row, click the list arrow and select Where from the list. Click the First Class column's Criteria row and type False.
Click the Run button on the toolbar.
Access displays the crosstab query, which only includes non-first class tickets.
Close the query without saving your changes.