All articles

Tables & data

Group table rows and add subtotals

Grouping turns a flat list into sections. An expense table grouped by category prints every Travel line together under a Travel header, then a Travel subtotal, then the next category — from the same rows, with nothing changed in your data. You can also group within groups, such as categories inside regions.

Before you start

  • In the hosted app, changing a template needs the editor role or higher (roles run viewer, editor, admin, owner). Local mode is single-user and has no roles.
  • You need a table that prints one row per item of a list, with sample or live data loaded so you can see the result.
  • A table can be grouped or have sub-rows, not both. If this table has sub-rows, remove them first.
  • While you are reviewing changes Buddy proposed, the properties panel is paused until you accept or discard them.

Group the rows

  1. Select the table — on the canvas in the Flow view, or in the Outline — and open the properties panel with the button at the far right of the app bar (tooltip Show properties panel). ⌘. (Ctrl+. on Windows) works too.
  2. On the Grouping line, which reads · none, press + Add level. A Level 1 card opens.
  3. In Group by, replace the starting value, item.Field, with the row field to group on, such as item.Category. If you gave the table its own Binding name, the starting value and the path use that name instead of item. A ⚠ means it does not resolve in the sample data. In the hosted app, when the template reads from a data source, Group by is a searchable list of the row's fields instead.
  4. Leave Order on A→Z, or choose Z→A to reverse the order of the groups.

The rows now print in one group per distinct value. Numbers sort as numbers, everything else (numbers stored as text included) alphabetically. Rows missing the field form one group, first under A→Z and last under Z→A. Inside a group, rows keep their order in your data.

Add a group header

A group header is a full-width row above each group, usually naming it.

  1. In the level card, open Group header (none).
  2. Press + Field. The new chip starts as group: the value this group's rows share.
  3. To put words in front, press + Text, type them, then press ↑ in that chip's ⋯ options to move it first.

A header can also use groupIndex (the group's position, from 0), groupCount (the number of groups at its level — for a second level, within the same first-level group) and parentGroup (the value of the group one level up). For a date or amount, give the group run a format — see Format values. First-level headers print bold on a grey band.

Add a subtotal row

  1. In the level card, open Subtotal row (none) and press + Add subtotal row. One empty cell appears per column, named after its header.
  2. Open the cell for your first column and type a label such as "Subtotal" in its empty text chip.
  3. Open the cell for the amount column, press + Total and open the new chip's ⋯.
  4. Value path starts at the field the column shows, such as item.Amount (or line.Amount when the table has its own Binding name such as line); change it to add up a different field. When the template reads from a data source, Value path can be a searchable list of the row's fields instead. Leave Collection as groupItems, which means this group's rows.
  5. To change sum to avg, count, min or max, use the operation menu. The total starts in Currency format; switching to count sets it back to a plain number.

A total skips rows whose value is missing or not a number, and prints empty when no row has one. The subtotal row prints after its group's last row, in bold with a rule above it. Remove subtotal row takes it away.

Group within groups

Press + Add level again for Level 2 and choose a second Group by field. Grouping by region, then category, prints a region's header, each of its categories with their own header, rows and subtotal, then the region's subtotal. Second-level headers print indented on a lighter band, and second-level headers and subtotals in normal weight. A third level and deeper print like the second, each indented a little further. ✕ on a level card removes that level.

Add a grand total

The footer row is separate from grouping. In Columns, open the amount column's card with ▸, open Footer / total and press + Total; it starts as a sum of that column's field. The footer adds up every row in the list, whatever the grouping, and prints once, in bold, after the last group. Label it with + Text in the first column's footer.

How it prints across pages

In the Paged view and the PDF:

  • The column header row repeats at the top of every page the table continues onto.
  • A row never splits across two pages.
  • A group header stays with its group's first row, and a subtotal row with its group's last row.
  • A group header prints once, where its group starts; it is not repeated when the group runs onto the next page.
  • The footer row prints once, after the last row.

No setting starts each group on a new page.

Good to know

  • While a table has sub-rows, + Add level is unavailable, and opening Grouping shows Grouping isn’t available while this table uses sub-rows (remove the sub-rows first).
  • A group header or subtotal prints once per group, so a plain row field there, such as item.Product, prints empty and is flagged This field renders empty here. In a header, use group or a field of the whole record; in a subtotal, a + Total.
  • The subtotal row follows the columns: adding a column adds an empty subtotal cell, duplicating one copies its subtotal cell, removing one removes it, and moving one moves its subtotal cell with it.
  • In a grouped table, index keeps each row's position in the original list, so row numbers built from it do not run 1, 2, 3 down the page.
  • A new + Field in a group header or subtotal starts as group and is typed, not picked, so you can change it to groupIndex, groupCount or parentGroup, or to a field of the whole record.
  • A group header cannot be removed once added. Remove the level with ✕ and add it again.

What next