Others

How to Transpose Access Query Results into Date, Gender, and Count

Camila MilosovichCamila Milosovich Oct 21, 2026 869 views

Question details

The user needs to normalize a Microsoft Access table or query by combining separate Male and Female columns into unified Date, Gender, and Count fields.

How to Transpose Access Query Results into Date, Gender, and Count
Product
Microsoft Access
Device & OS
not provided
Scenario
Restructuring database query outputs to unpivot column-based demographic data into row-based records for easier analysis.
Observed behavior
The data is currently separated into individual columns for Male and Female counts, but the goal state requires it to be grouped by Date and a single Gender column containing both categories.
Before you start

Ensure you know the exact names of your source table or query, as well as the specific column names for Date, Male, and Female, before writing the SQL statement.

Solution 1Recommended

Use UNION ALL and GROUP BY in SQL View

Combine the separated columns into rows using a UNION ALL subquery, and then aggregate the results with a main GROUP BY query.

Microsoft Access does not have a native 'Unpivot' function like Excel Power Query, but you can achieve the exact same normalization by writing a custom SQL query. A UNION ALL statement stacks the Female and Male columns on top of each other, assigning a literal 'F' or 'M' value to a new Gender column.

Wrapping this UNION ALL subquery inside a main query allows you to use the SUM function and GROUP BY clause to consolidate the data properly.

1
Open Query Design in SQL View

Open your Microsoft Access database. Go to the 'Create' tab on the ribbon and click 'Query Design'. Close the 'Show Table' dialog box without adding anything, then click the 'SQL View' button in the top-left corner of the Design tab.

2
Construct the UNION ALL subquery

Create the inner query that unpivots your data. For example: SELECT [Date], 'F' AS Gender, Female AS N FROM Shelf WHERE Female > 0 UNION ALL SELECT [Date], 'M' AS Gender, Male AS N FROM Shelf WHERE Male > 0.

3
Wrap with the main GROUP BY query

Enclose the subquery and add the aggregation logic. Type: SELECT [Date], Gender, Sum(N) AS CountOfGender FROM ( [Insert Subquery Here] ) AS Q GROUP BY [Date], Gender;

4
Run and test the query

Click the 'Run' button (the red exclamation mark icon) in the Query Design ribbon. Review the datasheet view to ensure your Date, Gender, and CountOfGender fields are correctly populated.

Use UNION ALL and GROUP BY in SQL View
Applying Filters: If you need to filter the data further based on parameters from a previous query, you can add a WHERE clause to the main query before the GROUP BY statement.
Free Microsoft Office alternative

Analyze Data Easily with WPS Spreadsheet

While Microsoft Access is a powerful relational database tool, many data summarization and unpivoting tasks can be handled much faster using Pivot Tables in a spreadsheet. WPS Office offers a completely free, lightweight alternative to Microsoft Office, providing powerful data analysis features without the steep learning curve of SQL.

  1. 1. Download and Install: Get the free WPS Office installer from the official website and complete the quick installation process.
  2. 2. Open Your Data File: Launch WPS Spreadsheet and easily open your exported Access tables or Excel files.
  3. 3. Analyze with Pivot Tables: Navigate to the Insert tab, select Pivot Table, and drag your fields to quickly summarize and reshape your data.
Completely free and lightweight Office suiteFully compatible with Microsoft Excel formats (.xlsx, .xls, .csv)Intuitive Pivot Tables for easy data grouping and transpositionFamiliar user interface requiring zero learning curve
microsoft office alternative - wps office

Frequently Asked Questions

Can I unpivot data in Access using a built-in wizard instead of SQL?

No, Microsoft Access does not have a built-in Unpivot wizard. While the Crosstab Query Wizard can pivot rows into columns, reversing the process (unpivoting columns into rows) requires writing a custom UNION or UNION ALL query in SQL View.

What is the difference between UNION and UNION ALL in Access SQL?

A UNION query automatically removes duplicate records from the combined dataset, which takes extra processing time. A UNION ALL query includes all records, including duplicates. For unpivoting and counting demographic data, UNION ALL is faster and prevents accidental data loss from matching counts.

Why am I getting a 'Syntax error in UNION query' message?

This usually happens if the number of columns, or the data types of the columns, do not perfectly match across all SELECT statements within your UNION query. Ensure both the Male and Female SELECT statements output exactly three columns: Date, Gender string, and the numeric Count.

How do I format the Date column in my grouped Access query?

You can use the Format() function within your SELECT statement. For example, change SELECT [Date] to SELECT Format([Date], 'yyyy-mm-dd') AS FormattedDate, making sure to apply it in both the subquery and the main grouping query.