- Open a form or report in Design view.
- Click the Text Box tool on the toolbox.
- Do one of the following:
- To calculate a total or average for a group of records, add the text box to the group header or footer.
- To calculate a grand total or average for all records in a form or report, add the text box to the header or footer of the form or report.
- Select the text box, and then click Properties on the toolbar.
- In the ControlSource property box, type an expression that uses the Sum function to calculate a total or the Avg function to calculate an average.
In a Microsoft Access database (.mdb), for a form or report, you can click the Build button to use the Expression Builder to create the expression.
This control calculates the total sales for each order.
This control calculates the total sales for all orders in the report.
Notes
-
The Employee Sales by Country report in the Northwind sample database has an example of group totals and a grand total. To view this report, point to Sample Databases on the Help menu, click either Northwind Sample Database or Northwind Sample Access Project, and then open the Employee Sales by Country report in Design view.
-
When computing a total in a form or report in Design view with an aggregate function such as Sum or a domain aggregate function such as DSum, you can't use the name of a calculated control in the Sum function. You must repeat the expression in the calculated control. For example:
=Sum([Quantity] * [UnitPrice])
However, if you have a calculated field in an underlying query, for example:
=ExtendedPrice: [Quantity] * [UnitPrice]
you can use the name of that field in the Sum function, as shown here:
=Sum([ExtendedPrice])
Calculate a percentage value on a report
- Open a report in Design view.
- Click the Text Box tool on the toolbox.
- Do one or both of the following:
- If the report does not calculate group totals, click the group footer to add a text box to display the group totals.
- If the report does not calculate a grand total, add a text box to the report footer to display the grand total.
- Do one or both of the following:
-
To calculate what percentage of a group total or the grand total each item is, add a text box to the detail section.
-
To calculate what percentage of the grand total a group of items is, add a text box to the group header or footer.
Note If your report includes multiple group levels, place the text box in the header or footer of the level for which you want Microsoft Access to calculate a percentage.
-
- Select the text box, and then click Properties on the toolbar.
- In the ControlSource property box, type an expression that divides the smaller total by the larger total of which the smaller total is a part.
In a Microsoft Access database (.mdb), you can click the Build button to use the Expression Builder to create the expression.
The percentage of the grand total is calculated by ...
... dividing the value of the DailyTotal control in the ShippedDate footer ...
... by the value of the GrandTotal control in the report footer.
- Set the Format property of the text box to Percent.
Note The Employee Sales by Country report in the Northwind sample database has an example of percentages. To view this report, point to Sample Databases on the Help menu, click either Northwind Sample Database or Northwind Sample Access Project, and then open the Employee Sales by Country report in Design view.
Calculate a total or other aggregate values on a data access page
Calculate an aggregate value
When the control you want to use to calculate the aggregate value is already on the page
- Open the data access page in Design view.
- Select the text box or bound span control that contains the values you want to aggregate.
- On the toolbar, click the arrow next to the AutoSum
button, and then select the aggregate function that you want to use.
The results you see depend on the type of page and the group level to which the selected control belongs.
If the bound control belongs to Then An ungrouped page, or the outermost group level on a grouped page Microsoft Access creates a new group level, and adds a bound span control to the footer section of the new group level. An inner group level on a grouped page Access adds a bound span control to the footer section of the parent group level. If the footer section is not shown, the aggregate control is placed in the header section of the parent group level. Note The list of aggregate functions that you see in the AutoSum list depends on the type of data you want to summarize. For numeric values, you can choose from Sum, Average, Min, Max, Count, StDev, and Any. For text, date, and time values, you can choose from Min, Max, Count, and Any.
When the control you want to use to calculate the aggregate value is not on the page
This procedure does not apply to ungrouped pages. The page will not show the detail values of the field that is being used to calculate the aggregate values. If you want to show both individual and aggregate values, add the bound control to the page, and follow the previous procedure.
- Open the data access page in Design view.
- If the field list is not displayed, click Field List on the View menu.
- In the field list, click the field that has the values you want to aggregate.
- Drag the field to the header or footer section where you want to show the aggregate values. For example, if the page has two group levels, Orders and Order Details, you can drag a field from the Order Details table to the header or footer section of the Orders group level.
The Layout Wizard dialog box appears.
-
In the wizard dialog box, select the layout you want, and click OK.
Microsoft Access creates a bound span control in the target section. The control will use the Sum function for numeric values and the Count function for all other data types.
Calculate subtotals and grand totals
Calculate a total based on an aggregate value
- Select the aggregate control, and then click AutoSum on the toolbar.
Microsoft Access creates a bound span control in the footer section of the next higher group level. If the aggregate control belonged to the highest group level, a new group level will be created. The new control will use the same aggregate function as the aggregate control on which it is based.
Notes
- You can set the properties of the aggregate control, and move, resize, or format the control to make it look the way you want.
- You can change the control's aggregate function by setting the control's TotalType property to the aggregate function you want. When you change the aggregate function, the default alias and caption of the control change to reflect the underlying aggregate function. To prevent the control name from changing, type a new alias for the control in its ControlSource property. User-specified aliases don't change when the aggregate function is changed.
- Changing the aggregate function of a control does not affect other aggregate controls, such as those that calculate subtotals or grand totals.
In PivotTable view
Calculate a total on a datasheet or form
-
Open a datasheet or form in PivotTable view.
-
Do one or more of the following:
You can add total fields to the detail area, but not to the row, column, or filter area.
- Open a datasheet or form in PivotTable view.
-
Click the field that contains the values you want to summarize.
-
On the PivotTable toolbar, click AutoCalc , and then click the summary function you want.
You can add a detail or total field that uses an expression to calculate data.
- Open a datasheet or form in PivotTable view.
-
On the PivotTable toolbar, click Calculated Totals and Fields , and then do one of the following:
-
To create a detail field, click Create Calculated Detail Field.
-
To create a total field, click Create Calculated Total.
-
-
In the Properties dialog box, type the expression you want on the Calculation tab, and then click Change.
To add field references, select a field that you want to use from the Insert Reference To box, and then click the Insert Reference To button.
Notes
- To edit the expression that is being used in a calculated field, select the field, edit the expression, and then click Change on the Calculation tab of the Properties dialog box. The field values will be automatically recalculated using the new expression.
-
By default, total fields that summarize numeric data use the Sum summary function. Fields that summarize other types of data use the Count summary function.