Skip to main content Pricing for individuals For families For single users For premium users For students Learn more Pricing for business For small business For schools For government Pricing for enterprise For enterprise For frontline workers For nonprofits For government Meet Copilot Copilot Chat AI Agents Daily Prompt Guide Plans and pricing Microsoft Teams Word Excel PowerPoint Outlook OneDrive SharePoint Planner See all apps and services Microsoft Office Windows 365 Microsoft Viva Microsoft Edge Microsoft Agent 365 Plans and pricing Learn to use Copilot Copilot learning center Cost savings Accounts and billing FAQ Setup and install Templates Training What's new Microsoft Frontier Program Microsoft 365 Roadmap Microsoft 365 Blog Small Business Resource Center Self-help resources Billing support Community Contact Microsoft Support Self-help resources Admin self-help Support plans Find a partner Contact Sales Community Self-help resources Educator Center Request support Contact Microsoft Support Community Become a partner Partner resources See all support Try for free

Try Microsoft 365 Copilot

Available on desktop and mobile devices

(Guest blogger, Molly Pell is a Senior Systems Analyst at FMS, Inc., a leading Access applications company, which designs custom solutions to improve operations for small and large organizations in all sectors.)

A well designed database stores data in a normalized format with dates defined in a field so that new data is simply added as additional records. However, people want to see data with dates grouped by columns.

This can be done by using a crosstab query. However, when creating reports based on crosstab queries, we need to control the specific column names that are returned by the query. Otherwise, the report cannot refer to the query’s fields.

As an example, we will use a slightly modified version of the Northwind 2007 Template. The following crosstab summarizes the sales for previous year, with a column for each month:

Access 2010 Cross Tab Report

The query sql looks like this:

TRANSFORM Sum(CCur([Quantity]*[Unit Price]*(1-[Discount]))) AS Price

SELECT [Order Details].[Product ID]

FROM [Order Summary] INNER JOIN [Order Details] ON [Order Summary].[Order ID] = [Order Details].[Order ID]

WHERE (((Format([Order Date],"yyyy"))=Format(Date(),"yyyy")-1))

GROUP BY [Order Details].[Product ID]

ORDER BY Format([Order Date],"mmm")

PIVOT Format([Order Date],"mm");

This works great until you run into a month that doesn’t have any sales. For example, assume that you have no sales in July:

Access 2010 Cross Tab Report with missing data

Notice that in addition to being sorted undesirably, there is no column for July. This poses a problem, for example, if you want to use the crosstab query as the datasource for a report, Access 2010 reports reference field names directly. If you want to use a crosstab query as the RecordSource of a report, its column names should be static.

Use the PIVOT IN Clause to Specify Required Column Names

In Design view, open the Property Sheet for the query, and set the Column Headings property to show the desired columns in the desired order:

Design View of Access 2010 Cross Tab Report

The query sql looks like this:

TRANSFORM Sum(CCur([Quantity]*[Unit Price]*(1-[Discount]))) AS Price

SELECT [Order Details].[Product ID]

FROM [Order Summary] INNER JOIN [Order Details] ON [Order Summary].[Order ID] = [Order Details].[Order ID]

WHERE (((Format([Order Date],"yyyy"))=Format(Date(),"yyyy")-1))

GROUP BY [Order Details].[Product ID]

ORDER BY Format([Order Date],"mmm")

PIVOT Format([Order Date],"mmm") IN ("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");

Now that you have static column names, you can use the query to drive a report, referring to the known query names:

Access 2010 Cross Tab Query

For more information about using crosstab queries on reports, check out our tip here http://www.fmsinc.com/MicrosoftAccess/query/crosstab-report/index.html.