cat / 012
clone

a spreadsheet for the terminal: lotus 1-2-3 looks, google sheets keys and formulas, one go binary

cat/module-path
012 / docs / sheets / pivots.md
pivots.md 4.2K rendered
1---2title: "Pivot tables"3sidebar_position: 84---56# Pivot tables78![Building a pivot table of revenue by region and quarter, then changing its data](../media/pivot.gif)910Data > Pivot table summarizes the selection, or the table around the11active cell, on a new sheet named `Pivot Table 1`, as Sheets' Insert >12Pivot table does. The data's first row names the fields. The pivot editor13opens docked at the right of the grid, with the results updating behind it:1415- **Rows** group the data by a field's values, one row per value; with two16 or more, the groups nest and each outer group gets a subtotal row.17- **Columns** spread the groups across columns by a field's values; with18 two or more, each outer group gets a subtotal column (`East Total`)19 after its last column.20- **Values** summarize a field for each group: SUM, COUNTA, COUNT,21 COUNTUNIQUE, AVERAGE, MAX or MIN (Sheets' "Summarize by"), shown as they22 are or as a share of their row, column or grand total ("Show as").23 A new value is summed when its field holds numbers, and counted24 otherwise. Its header is Sheets' `SUM of Units` until you rename it.25- **Filters** leave out rows by a field's values or a condition, in the26 same picker as a filter's column.27- **Grand total row** and **Grand total column** add Sheets' totals, and28 turn the subtotal rows and columns on and off with them.2930Up and Down pick a line. Space adds a field to the section it's on (pick31it from the fields of the data, type to narrow the list), opens a filter's32values, or flips a toggle; Space on the data range points at a new one on33its sheet. On a row or column field, Left and Right order its groups A to34Z, Z to A, or by a value's total, smallest or largest first, and35Shift+Up and Shift+Down move it before or after the others, which changes36how the groups nest. On a value, Left and Right change how it's37summarized, S how it's shown, and R (or F2) renames it on the context38line, the name heading its columns; an empty name goes back to Sheets'.39A value keeps its name when its summary changes. Del removes a field. Every change is an40undo step; Enter keeps them, Esc undoes them, and removes a pivot just41created. Data > Edit pivot table opens the editor again.4243Groups follow Sheets: text ignoring case (`east` joins `East`), numbers44and dates by value, with the source's format, so dates show as dates.45Numbers and text never share a group: `1` and the text `'1` are two.46Groups sort numbers first, then text, booleans and errors, and blank47cells last; as in Sheets, the group of blank cells has a blank label,48and its subtotal is just `Total`. Sorting an outer column field by a49value's total orders whole outer groups, so their columns stay50together. Rows blank across the whole range are51left out, so a range can reach past the data. SUM, AVERAGE, MIN and MAX52keep the column's number format: the column's own when it has one, else53the format most of its numbers show in (ties go to the first), so one54price typed as `$9,000` among `$2.50`s doesn't turn every total into55whole dollars. A group's label shows in the format of its first cell. An56error in a summed column shows as that error, as SUM would.5758The results are live: any change to the data, typed, pasted, filled or59computed by a formula, recomputes the pivot, and rows or columns inserted60inside the range widen it. Formulas can read the results (`='Pivot Table611'!B5`), and copying them pastes their values. The results themselves62can't be edited, as in Sheets: typing, pasting, clearing, formatting,63sorting or inserting rows or columns over them is refused with a note on64the context line. A pivot shows `#REF!` in A1, explained on the context65line, when its data's sheet is deleted or when its results would66overwrite a cell typed next to them; undo or moving the cell brings it67back. The sheet's columns widen to fit the results until you set a width68yourself.6970## Frequency tables7172Data > Frequency table (column stats), or Alt+Shift+F (VisiData's73Shift+F; plain Shift+F types an F), counts each value of the active74column of the table around the active cell on a new sheet, `Frequency of75<field>`: the value, how many rows have it and their percentage, most76frequent first, with a Grand Total. Blank cells are counted too. It is a77pivot table like any other, so it stays live, and the pivot editor78changes it.