Calculate a total or other aggregate values

Microsoft Office Access 2003

  1. Open a form or report in Design view.
  2. Click the Text Box tool Button image on the toolbox.
  3. 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.
  4. Select the text box, and then click Properties Button image on the toolbar.
  5. 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.

    ShowTip

    In a Microsoft Access database (.mdb), for a form or report, you can click the Build button Button image to use the Expression Builder to create the expression.

    ShowExample

    Controls that calculate totals in the group footer and report footer

    Callout 1 This control calculates the total sales for each order.

    Callout 2 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])

ShowCalculate a percentage value on a report

  1. Open a report in Design view.
  2. Click the Text Box tool Button image on the toolbox.
  3. 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.
  4. 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.

  5. Select the text box, and then click Properties Button image on the toolbar.
  6. 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.

    ShowTip

    In a Microsoft Access database (.mdb), you can click the Build button Button image to use the Expression Builder to create the expression.

    ShowExample

    Text boxes that calculate percentages shown in Design view

    Callout 1 The percentage of the grand total is calculated by ...

    Callout 2 ... dividing the value of the DailyTotal control in the ShippedDate footer ...

    Callout 3 ... by the value of the GrandTotal control in the report footer.

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

ShowCalculate a total or other aggregate values on a data access page

Calculate an aggregate value

ShowWhen the control you want to use to calculate the aggregate value is already on the page

  1. Open the data access page in Design view.
  2. Select the text box or bound span control that contains the values you want to aggregate.
  3. On the toolbar, click the arrow next to the AutoSum Button image 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.

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

  1. Open the data access page in Design view.
  2. If the field list is not displayed, click Field List on the View menu.
  3. In the field list, click the field that has the values you want to aggregate.
  4. 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.

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

ShowCalculate a total based on an aggregate value

  • Select the aggregate control, and then click AutoSum Button image 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

ShowCalculate a total on a datasheet or form

  1. Open a datasheet or form in PivotTable view.

  2. Do one or more of the following:

    ShowAdd a total field

    You can add total fields to the detail area, but not to the row, column, or filter area.

    1. Open a datasheet or form in PivotTable view.
    2. Click the field that contains the values you want to summarize.

    3. On the PivotTable toolbar, click AutoCalc Button image, and then click the summary function you want.

    ShowAdd a calculated total field

    You can add a detail or total field that uses an expression to calculate data.

    1. Open a datasheet or form in PivotTable view.
    2. On the PivotTable toolbar, click Calculated Totals and Fields Button image, 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.

    3. In the Properties dialog box, type the expression you want on the Calculation tab, and then click Change.

      ShowTip

      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.