8. Grouping and Ungrouping a Table

Just as you can create a column containing a nested table in table data, you can also modify a table view by grouping it by the values of a particular column so that for every unique value in the column, there is a subordinate table consisting of all rows that contain this value. Put simply, if you group the table in our example by the Artist column, you will get a table of all artists, where every artist will have a subordinate table containing all albums by that artist. To do this, follow these steps:
1.
Right-click the Artist column header and select Group by Column from the context menu.
2.
A table is created, in which every artist is assigned a list of his/her albums shown as a subordinate table. The list is displayed under a column labeled Group.

Grouping Cancellation

If you wish to cancel the grouping, right-click the Group column header, and select Ungroup Sequence. You can also cancel all changes made to a view using the Reset View command from the context menu.

Ungrouping a Nested Table

Ungrouping a nested table (sequence) is an inverse operation to grouping. Suppose you have the table modified in the previous chapter (file Examples\Chapter 07.s-d), and you wish to ungroup the nested tables containing album orders. To do this, follow these steps:
1.
Right-click the Order column header and select Ungroup Sequence from the context menu.
2.
The resulting table contains one row per order, that is, it has no subordinate tables. This is useful for example if you need to present summarized information about all orders. Those rows of the original outer table, that contained an empty nested table, are not displayed at all.

Grouping by Another Column

The table previously ungrouped can be regrouped by a column other than the original one – for example by the Name column (i.e. the customer’s name). This step produces lists of albums assigned to individual customers (whereas the original table contained lists of customers assigned to individual albums).

Grouping by a Computed Column

You can also group a table by a computed column. Take the initial table from the first lesson (file Examples\Chapter 01.s-d). Suppose you wish to divide the albums in the list by the decade in which they were released. To do this, follow these steps:
1.
Create a computed column containing the decade: select New Column from the context menu. In the dialog, set the Column insertion level to View, Name to decade, Data type to Computed, Result data type to Integer number, and Setter function to (year div 10) * 10 (i.e. divide year by 10 using integer division and multiply the quotient by 10 again – lowest digit places are removed).
2.
Group the table by the decade column. If you order the table by this column on top of that, the result will look like this:

Further Information

The following chapters of the Reference Guide contain detailed information on the discussed topic:
●
Enki Language – language used for the specification of expressions