How to Transpose Access Query Results into Date, Gender, and Count
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.

- 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.
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.
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.
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.
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.
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;
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.

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. Download and Install: Get the free WPS Office installer from the official website and complete the quick installation process.
- 2. Open Your Data File: Launch WPS Spreadsheet and easily open your exported Access tables or Excel files.
- 3. Analyze with Pivot Tables: Navigate to the Insert tab, select Pivot Table, and drag your fields to quickly summarize and reshape your data.

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.




