Calculate Tardy Percentages by Professor Using Group By in Access
Question details
The user needs to calculate the percentage of tardy records for each professor using an aggregate query in Microsoft Access without causing errors.

- Product
- Microsoft Access
- Device & OS
- not provided
- Scenario
- Creating an aggregate SQL query to summarize Boolean conditions (tardy vs. on time) and calculate a percentage grouped by a specific text field.
- Observed behavior
- Adding the professor field without grouping it correctly results in an aggregate-function error, or the calculated totals do not add up properly.
Verify that your table name is correct and that the 'Tardy' field contains consistent Boolean (Yes/No) or numeric data so the mathematical query evaluates it properly.
Use an SQL GROUP BY Clause for the Aggregate Query
Applying a GROUP BY clause ensures that non-aggregated fields (like Professor) are properly structured, which resolves aggregate-function errors and yields correct percentage totals.
In Microsoft Access SQL, any field included in your SELECT statement that isn't wrapped in a mathematical function (such as Sum or Count) must be explicitly listed in a GROUP BY clause.
Since Microsoft Access evaluates a Boolean 'True' as -1, you can use a negative Sum function against your condition to return a positive count of matching records. Dividing this by the total Count(*) provides your percentage.
Open your Access database, navigate to the Create tab on the top ribbon, and select Query Design.
Close the 'Show Table' dialog box if it appears. Right-click the query tab or use the View dropdown on the ribbon, and select SQL View.
Type the following SQL statement into the editor: SELECT Professor, -Sum(Class.Tardy=1)/Count(*) AS [Tardy Percent] FROM Class GROUP BY Professor;
Click the Run button (red exclamation mark) in the Query Design ribbon to execute the statement and review the grouped results.

Analyze and Group Data Seamlessly with WPS Office
While Microsoft Access requires SQL knowledge for database queries, you can perform similar data grouping and percentage calculations effortlessly using PivotTables in WPS Spreadsheet. It offers a free, lightweight, and highly compatible alternative for data analysis.
- 1. Export Access Data: Export your Microsoft Access table to an Excel format (.xlsx) and open the file in WPS Spreadsheet.
- 2. Insert a PivotTable: Highlight your entire data range, navigate to the Insert tab on the top ribbon, and click PivotTable.
- 3. Group and Calculate: Drag the 'Professor' field to the Rows area and the 'Tardy' field to the Values area. Change the Value Field Settings to display data as a '% of Grand Total'.

Frequently Asked Questions
Why do I get an aggregate-function error in Microsoft Access?
This error triggers when your SELECT statement includes a field that is not part of an aggregate function (like Sum, Count, or Avg) and is also missing from your GROUP BY clause. Ensure all standalone fields are properly grouped.
Why does Access use a negative Sum to count matching records?
In Microsoft Access, a Boolean 'True' condition is stored as -1, and 'False' is stored as 0. Wrapping the condition in a negative Sum (e.g., -Sum([Tardy]=1)) converts the resulting negative number into a positive count of records matching the condition.
Can I calculate percentages in the Access Query Design view instead of SQL?
Yes. In the Query Design view, click the 'Totals' button (Sigma icon) on the ribbon. Keep the 'Total' row for the Professor field as 'Group By'. In an empty column, type an expression like `Tardy Percent: -Sum([Tardy]=1)/Count(*)` and change its 'Total' row to 'Expression'.




