The rows of a result are grouped by the values of one or more columns, without writing a `group by` in the statement. Every value becomes a group which can be opened and closed, with the rows underneath it. The examples use the result of the statement described in [[Invantive Query Tool Multi-Platform/Results|Results]]. Grouping with a bar of chips, headers with a count and opening or closing all groups are available from release 28.0.
![[20261008-qtm-results-groups.png]]
## Grouping and Ungrouping
Above the column headings stands a bar with the text "Drag a column header here to group by that column." A heading is dragged onto the bar to group by that column. A heading can also be grouped without the pointer, through "Group by this column" in the menu behind the button with three dots in the heading.
A column which is grouped appears in the bar as a chip with its caption, an arrow for the direction and a cross:
- The arrow turns the order of the groups between ascending and descending. The tool tip of the chip says "Click to toggle sort direction".
- The cross takes the column out of the grouping again, and so does "Remove grouping" in the menu of the heading. The sort which the grouping put on the column goes with it.
Several columns can be grouped one within the other. The first chip is the outer group.
## The Groups
Every group has a header row with the caption of the column, the value and the number of rows, such as `CATEGORY: Alpha (4)`. The arrow in front of the header opens and closes the group. The summaries of the group stand in the header; see [[Invantive Query Tool Multi-Platform/Summaries|Summaries]].
The name of a group is the value as the cell shows it, with the following exceptions:
- A date with a time is grouped by the calendar date, so a column of moments gives one group per day. A time of day is not grouped by its date.
- A yes or no value is "Yes" or "No" in the language of the product.
- The empty values form the group "(Blanks)".
The groups stand in the order of the column, ascending or descending as the chip says. The rows in a group stay in the order of the result, unless the result is sorted.
The buttons "Expand All" and "Collapse All" on the toolbar of the results open or close every group at once.
## A Column With Too Many Groups
Grouping on a column with a different value in every row, such as an identification, makes as many groups as there are rows. The grid refuses a grouping of which the number of groups multiplied by the number of rows passes 400,000,000, which is about 400 groups for 1,000,000 rows and 4,000 groups for 100,000 rows. The message names the column, the number of groups and the number of rows.
## Grouping in the Grid and in the Statement
Grouping in the grid keeps every row: the rows are put in groups instead of replaced by one row per value. A `group by` in the statement does replace them, so the individual rows never arrive. To look at the rows of one value among many, group in the grid. To count, add up or average over a large table, write the `group by` in the statement, since the work is then done where the data is.
Grouping covers the rows which are shown, so it follows a filter; see [[Invantive Query Tool Multi-Platform/Filtering Rows|Filtering Rows]]. An export follows the grouping: the workbook which "Export to Microsoft Excel" writes holds the groups as outline levels; see [[Invantive Query Tool Multi-Platform/Exporting Results|Exporting Results]]. A saved layout keeps the grouping; see [[Invantive Query Tool Multi-Platform/Display Layout|Display Layout]].
A new result of a statement starts without groups.