Add summary statistics

One of the advantages of creating a grouped DataWindow object is that you can have PocketBuilder calculate statistics for each group. To do that, you place computed fields that reference the group. Typically, you place these computed fields in the group's trailer band.

StepsTo add a summary statistic:

  1. Select Insert>Control>Computed Field from the menu bar.

  2. Click in the Design view where you want the statistic.

    The Modify Expression dialog box displays.

  3. Specify the expression that defines the computed field (see “Specifying the expression”).

  4. Click OK.

NoteA shortcut to sum values If you want to sum a numeric column, select the column in Design view and click the Sum button in the Controls drop-down toolbar. PocketBuilder automatically places a computed field in the appropriate band.

Specifying the expression

Typically, you use aggregate and other functions in your summary statistic. PocketBuilder lists functions you can use in the Functions box in the Modify Expression dialog box. When you are defining a computed field in a group header or trailer band, PocketBuilder automatically lists forms of the functions that reference the group.

Figure 22-10: Listing of functions in the Modify Expression dialog box

The sample shows the scrollable Functions box in the Modify Expression dialog box. Displayed are available functions in  alphabetical order.

You can paste a function into the expression, then replace the placeholder (such as #x) that is pasted in as a function argument with the appropriate column or expression.

For example, to count the employees in each department (group 1), specify this expression in the group trailer band:

Count( Emp_Id for group 1 )

To get the average salary of employees in a department, specify:

Avg( Salary for group 1 )

To get the total salary of employees in a department, specify:

Sum( Salary for group 1 )

Figure 22-11: Design view with group functions in trailer band

The sample shows the group trailer band with the words  Average Salary and the partially visible expression a v g ( salary for group 1 ). Also in the group trailer band are the words Total Salary and the partially visible expression sum ( salary for group 1 ).

Figure 22-12 shows the same DataWindow as it appears in the Print Preview view.

Figure 22-12: Print Preview view with group functions in trailer band

The sample shows the Print Preview view of a Data Window with a group presentation style, where the data is grouped by Department I D. The top row has labels for the Employee I D, First Name, Last name, and Salary columns. Below it at left is the header for the Department I D column and below that is the I D 500. The rows of data for the department start on the following line.  At bottom right are the words Average Salary: and a dollar amount, then the words Total Salary: and a dollar amount.