## Summary fields

A summary is a special kind of formula. A summary generates a count, average, sum, standard deviation or other transformation of a set of data values. A summary applies to a defined group of data.

### Inserting a summary field in a report

Summaries can be inserted in the report areas listed in Component placement. Before you can insert a summary field into a report, you need to define it. For details about how to define summaries, see Creating a summary.

To insert a summary field into a report, you can use either of the following two ways:

- Using dialog
  1. Select the DBField in the report to which you want the summary to be applied.
  2. Do one of the following:
     - Click Insert > Summary on the menu bar.
     - Click the Insert Summary button on the Insert toolbar
     - Right-click the DBField and select Summary Function from the shortcut menu.

     The Insert Summary dialog appears. See the dialog.

  3. From the Function drop-down list, specify the function of the summary.
  4. If the report is grouped, select to which group level the summary will be applied from the Group By drop-down list. If None is select, the summary will be added based on the whole report.
  5. If the group by field is of Numeric, String, Date or Time type, you can further select a special function to calculate the summary according to your requirements by selecting an item from the Special Function drop-down list. If Customize is selected, you can set the function by your own.
  6. Click the Insert button to insert the summary into the destination.
- By dragging and dropping

  Select the required summary from the Resource View panel, then drag it to the destination. If the given summaries are not what you want, click the <Add Summary...> item to create one as required.

When a summary field has been inserted into a report, you can customize its appearance and behavior by setting properties in the Report Inspector, which can be saved as a CSS style for future use (for details, see Creating a CSS style).

Notes:

- Summary fields can only be inserted into the header/footer/detail panel of a banded object or cells in the header/footer/detail panel of a table. However, if you have specified a group by field when creating the summary, it can be inserted into the corresponding group panels.
- If you insert a summary into the detail panel of a component, the name of the summary will automatically be inserted as a label into the corresponding header panel. Otherwise the summary and its name label will be placed in the same panel. If you do not want to insert the name label automatically, you can go to the Options dialog, select Component in the Category box and then uncheck the Insert field name with field option.

### Changing the display type of a summary field

The display type of a summary field can be changed according to your requirements, that is to say, you can map the summary field to another value or image to be displayed instead.

To change the display type a summary field:

1. Right-click the summary and select Display Type from the shortcut menu.
2. In the Display Type dialog, specify the required display type in the Type box, and set the options for the selected type in the Options panel.
3. Upon finishing, click the OK button to close the dialog.

For details about display types, see Changing the display type of a label.

### Adding conditional formats to a summary field

You can add some conditional formats to a summary field, then when the specified condition is fulfilled, the defined format will be applied to the field values for distinguishing.

To add conditional formats to a summary field:

1. Right-click the summary field and select Conditional Formatting from the shortcut menu.
2. In the Conditional Formatting dialog, click the button to add a condition as required.
3. Set the format that will be applied to the field values when the specified condition is fulfilled.
4. Repeat the above two steps to add more conditions and define the format for each condition as required.
5. When done, click OK to save the settings.

For more details about conditional formatting, see Adding conditional formats to a DBField.

See an example: The SampleComponents catalog, included with JReport Designer, contains reports that have examples of how each component type could be used in a report. For the summary field example, open `<install_root>\Demo\Reports\SampleComponents\UsingSummaries.cls`.