Table grouping

Tables provide a simple way to display structured data as plain and neat lists. Grouping table rows by a certain attribute allows to create logical entities while benefiting from a table layout.

In this tutorial you will learn to:
Group data within a table
Create space between groups
Print a footer per group

1 Group data within a table

Let's take the example of a marathon event with different race types, e.g. a kids race, a full marathon and a half marathon. The marathon categories further differentiate between male and female participants.

We have created a table to print a list of attendees with race results (learn here how to create a table and populate it with data).

Instead of showing a column with the race type we want to group by it. First we delete the column showing the race type and create another content row to display the race type: a double click on a column cell brings up table options in the menu bar for both tasks.

Then we select the newly added content row in the menu panel and apply a group expression in the print settings: ${race_type}
The content row with the group expression will be printed whenever the value of the group expression changes.
Finally we set the race type as group header to the first cell of the new content row.

2 Create space between groups

We want to further improve the table arrangement by adding an empty content row after each group. To make sure it's only printed when the group changes we also have to set the group expression in the print settings on the content row: ${race_type}

Alternatively to create space between groups it is also possible to force a page break after each group. This option is available in the print settings of a content row once a group expression is set.

3 Show a footer per group

Sometimes you might want to conclude each group with sub-totals, summaries or other data aggregations. For our use case we extend each group by printing the average time per race type. The average time must be part of the table's parameter list.

Let's add another content row right after the row holding the race details and add the parameter to be printed. Once again we make sure this content row is only printed when the group changes by setting the group expression in the print settings on the content row: ${race_type}

A group expression is all you ever need

A table can have numerous content rows. Using a group expressions on a content row ensures that the whole row is only printed when the group expression changes. If you use a content row without a group expression it is printed with every data row like in the example here where I removed the group expression for the race type.

ReportBro Screenshot showing result of grouping a table with missing group expression

Try it yourself: Download the report of this tutorial
Read here how to import the report into ReportBro Designer.

Want to know more about tables? Read our tutorials for
Creating tables,
Condition-based table column printing and
Table with dynamic columns

By the way, ReportBro is also available for everyone as open-source on github (see Download page). Star us on github if you like what you see!