cat / 012
clone

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

main
012 / docs / sheets / tables.md
tables.md 5.2K rendered
1---2title: "Tables"3sidebar_position: 134---56# Tables78A table is a named range whose first row names its columns, as in9Sheets' and Excel's tables. Formulas read it by those names,10`=SUM(Sales[Amount])`, so they keep reading the right cells as the table11grows and its columns move ([Structured references](../formulas/references.md#tables-by-column-name)).1213![The table Sales, its header styled and its rows banded, the pointer on its Amount column; the context line says how formulas read the column, and the total beside the table sums it](../media/table-dark.png#gh-dark-mode-only)14![The table Sales, its header styled and its rows banded, the pointer on its Amount column; the context line says how formulas read the column, and the total beside the table sums it](../media/table-light.png#gh-light-mode-only)1516## Making one1718Format > Convert to table (Ctrl+Alt+T) makes a table of the selection, or19of the data around the active cell, and asks for its name on the context20line (`Table1` to start). A name follows a named range's rules, letters,21digits, `_` and `.`, except that `Table1` is fine: only names Excel reads22as a cell are refused. Tables, named ranges and23[notebook outputs](#notebook-outputs-and-linked-files) share one set of24names, so a table can't take a name one of them has.2526The first row is the header row: each cell's text is its column's name.27A blank header is named after its place (`Column3`) and a repeat28numbered (`Amount2`), in the cell too, so the header shows what formulas29use. A selection of one row gains an empty row of data below it.3031The table above is A1:D7, named `Sales`: `Sales[Amount]` reads D2:D732and `Sales[#All]` reads A1:D7, and a value typed in row 8 joins it. On33a table's cell the context line names the table and the column, and34how a formula reads it: `Table Sales, column Amount: Sales[Amount] in35formulas`.3637## Growing, resizing and removing3839A table grows by the rows typed or pasted just below it, in the same40undo step as the entry, so Ctrl+Z takes the row back out. It grows by41rows only: a column added at its right joins it through Data > Table >42Resize table, which asks for the new range, pointed at from the43table's own, header row first.4445Rows and columns inserted inside a table widen it, and deleting some46narrows it; a column inserted comes in named from its (blank) header,47`Column2`. Deleting a table's header row removes the table. Cutting the48whole table and pasting it elsewhere, on this sheet or another, moves49it.5051Changing a header renames the column in every formula that reads it:52typing `Revenue` over `Amount` turns `Sales[Amount]` into53`Sales[Revenue]`. Columns moved, inserted or deleted rename nothing;54formulas reading a deleted column show `#REF!`.5556Data > Table > Rename table renames the table and every formula that57reads it. Data > Table > Remove table makes it plain cells again: the58cells stay, and formulas that read it read the same cells by address59(`Sales[Amount]` becomes `$C$2:$C$4`, `Sales[@Amount]` the cell in the60formula's own row, `$C3`). Data > Table > Tables lists every table and61notebook output: Enter goes to one, F2 renames it and Ctrl+D removes it.6263## Banding and the header style6465Data > Table > Banded rows shades every other data row, and Header style66draws the header row bold, underlined and in the theme's accent. A new67table has its header styled and no bands: Sheets bands its tables, but68the terminal's own palette has no shade subtle enough for every other69row, so bands are there when you want them. They are the `TableBand` and `TableHeader` roles of the70[theme](../terminal/themes.md): a scheme draws the band a shade off its71background. The header's bold and underline read without color72([UX](../contributing/ux.md#reading-without-color)); the band is73decoration only.7475## Sorting and filtering a table7677Sorting or filtering with the active cell in a table takes the table's78range, its header row kept in place: Data > Sort range sorts its rows by79the active column, and Data > Create a filter puts the filter on it. A80filter on a table's range follows the table as it grows or is resized.8182## Notebook outputs and linked files8384A notebook cell's output sent to a sheet, and a linked file, is a table85by the region's name, with no table of its own to make: `app[status]`86reads the `status` column of the output of the cell `app`, and `app`87alone its rows under the header. `nu.app` stays what it was, the whole88table header row included, the same cells as `app[#All]`. Its source89names and shapes it, so the table commands leave it alone, and a table90can't take its name ([Notebooks](../nushell/notebooks.md#send-to-a-sheet)).9192## Where 012 differs from Sheets and Excel9394- Copying, pasting and filling keep structured references as written:95 they name columns, not positions. Excel shifts `[Amount]` to the next96 column when a formula is filled right.97- A table has no totals row and no calculated columns: a formula typed in98 a table's column isn't filled down the column for you. An Excel table's99 totals row comes in as cells below the table ([Excel files](../files/excel.md#tables-in-excel)).100- A structured reference names its table, `Sales[@Amount]`, even inside101 it; Excel's `[@Amount]` alone isn't read.102- `[@Amount]` outside the table's data rows is `#REF!`, where Excel gives103 `#VALUE!`.