Pivot table

A pivot table groups the query result the way an Excel PivotTable does: rows, optional columns, and aggregated values.

The query should return grain-level rows (one order, one event, one line). The widget does the grouping. If you already GROUP BY everything in SQL, a regular table is simpler.

Rows

rowField is the field that becomes the left-hand row labels (region, product, customer name).

Columns

columnField is optional. When set, each distinct value becomes its own column (for example a column per month). When left blank, the widget makes one column per value field.

Values and aggregations

valueFields are the numeric (or countable) columns to summarize. Each value field has an aggregation:

  • Sum
  • Average
  • Count
  • Min
  • Max

aggregations stores the function per field name. Count is the right choice for an id column; sum is the right choice for an amount.

Chart options

  • Grand total row — default on.
  • Grand total column — default on, most useful when a column field is set.

Example query

SELECT
  region,
  plan,
  amount
FROM invoices
WHERE account_id = :customer_id

Map Rows to region, Columns to plan, Values to amount with aggregation Sum.