Pivot

Spread the values of one column across the top of the table. Get one row for each group.

What it does

Pivot builds a cross-tab. Each value in the column you choose becomes a new column header. Each cell holds one aggregated number.

Before. One row for each region and category:

regioncategoryrevenue
NorthLaptops1200
NorthPhones800
SouthLaptops950
SouthPhones400

After. Rows = region, Columns = category, Values = SUM of revenue:

regionLaptopsPhones
North1200800
South950400

The three fields

  • Rows (group by): the columns that stay on the left. You can pick more than one.
  • Columns (pivot on): one column. Each of its values becomes a header.
  • Values: the column to aggregate, plus the function to use.

Build a pivot table

  1. Type pivot in the Search transforms box, in the Pipeline panel.
  2. Select Pivot in the results. The panel opens below the grid.
  3. Open Select row grouping columns (leave empty for all)… and pick your row columns.
  4. Open Choose column whose values become headers… and pick one column.
  5. In Values, click a function: COUNT, SUM, AVG, MIN or MAX.
  6. Open Choose value column… and pick the column to aggregate.
  7. Read Pivot Preview. It shows up to five result rows.
  8. Click Apply.

The grid updates at once. The step appears in your pipeline, where you can edit or delete it later.

Which function to use

  • COUNT counts the rows in each cell. It works with any column.
  • SUM and AVG need a number column.
  • MIN and MAX give the smallest or the largest value in the cell.

Tips

  • Click SUM or AVG first. The Values list then shows only number columns.
  • Leave Rows (group by) empty to group by all the other columns.
  • Each column that you use disappears from the other two lists. This stops a double pick.
  • Every different value in the header column becomes a new column. Check the value count first with the small grid icon next to the column name.
  • Use Unpivot to turn a pivot table back into long rows.

For SQL users

The step runs as a DuckDB PIVOT statement:

PIVOT (SELECT "region", "category", "revenue" FROM data) ON "category" USING SUM("revenue")
Try Pivot with sample data →

Related Operations