TABLE (FirstColumn, Column...) TABLE (FirstColumn; Column...)

FirstColumn

The first column, as an array holding one value per row. Its name is the name you give this parameter.

Column

An additional column, as an array holding one value per row. Its name is the name you give this parameter. This array must be identical in size to the other columns.

Returns

An array of values, one per row, whose members are named by the names given to the parameters. A #VALUE! error is returned if the columns are not of equal length.

Returns a table, built from one array per column. TABLE (Kind: { "Shirt", "Jacket" }, Price: { 29, 149 }) TABLE (Kind: { "Shirt"; "Jacket" }; Price: { 29; 149 }) returns a table of two rows, whose columns are named Kind and Price .

A table is an array of RECORD values, where each element is one row. TABLE is a convenience: it accepts a column at a time, which is the shape data usually arrives in, and assembles the rows for you.

A column is read using ! , which returns the whole column as an array:

TABLE (Kind: { "Shirt", "Jacket" }, Price: { 29, 149 })!Price
TABLE (Kind: { "Shirt"; "Jacket" }; Price: { 29; 149 })!Price

That formula returns { 29, 149 }{ 29; 149 }.

All columns must have the same number of elements, as every row needs a value in every column. A #VALUE! error is returned if they do not.

A value which is an error does not make the whole table an error. The other values can still be read. In this formula, the price of a hat cannot be found, and the formula returns the array { 29, NA () }{ 29; NA () }:

TABLE (Kind: { "Shirt", "Hat" }, Price: XLOOKUP ({ "Shirt", "Hat" }, { "Shirt", "Jacket" }, { 29, 149 }))!Price
TABLE (Kind: { "Shirt"; "Hat" }; Price: XLOOKUP ({ "Shirt"; "Hat" }; { "Shirt"; "Jacket" }; { 29; 149 }))!Price

TABLE and arrays of records are the same thing

TABLE builds an array of RECORD values, and nothing more. These two formulas are fully equivalent:

TABLE (Kind: { "Shirt", "Jacket" }, Price: { 29, 149 })
TABLE (Kind: { "Shirt"; "Jacket" }; Price: { 29; 149 })

{  RECORD (Kind: "Shirt", Price: 29), RECORD (Kind: "Jacket", Price: 149) }
{  RECORD (Kind: "Shirt"; Price: 29); RECORD (Kind: "Jacket"; Price: 149) }

Both return the same table, and anything one can do, so can the other.

TABLE is worth using anyway. Data usually arrives as a column at a time rather than as a row at a time, which is the shape TABLE accepts. The equivalent array of records repeats every column name once per row, which grows tiresome quickly. A table of three columns and twenty rows names its columns three times using TABLE and sixty times when written out.

Looking up values in a table

XLOOKUP searches one column and returns the corresponding value from another. Name the table using LET, so that it need only be written once:

LET (Products := TABLE (Kind: { "Shirt", "Jacket" }, Price: { 29, 149 }), XLOOKUP ("Jacket", Products!Kind, Products!Price))
LET (Products := TABLE (Kind: { "Shirt"; "Jacket" }; Price: { 29; 149 }); XLOOKUP ("Jacket"; Products!Kind; Products!Price))

That formula returns 149, the price of the jacket.

XLOOKUP can also return a whole row rather than a single value, by searching a column and returning the table itself. Refer to the XLOOKUP documentation for that technique.

Examples

TABLE (Kind: { "Shirt", "Jacket" }, Price: { 29, 149 })!Price
TABLE (Kind: { "Shirt"; "Jacket" }; Price: { 29; 149 })!Price

Returns { 29, 149 }{ 29; 149 }, the Price column.

LET (Products := TABLE (Kind: { "Shirt", "Jacket" }, Price: { 29, 149 }), XLOOKUP ("Jacket", Products!Kind, Products!Price))
LET (Products := TABLE (Kind: { "Shirt"; "Jacket" }; Price: { 29; 149 }); XLOOKUP ("Jacket"; Products!Kind; Products!Price))

Returns 149, the price of the jacket. LET names the table, so that both columns can be read from it without writing it twice.

COUNT ( TABLE (Kind: { "Shirt", "Jacket" }, Price: { 29, 149 })!Price)
COUNT ( TABLE (Kind: { "Shirt"; "Jacket" }; Price: { 29; 149 })!Price)

Returns 2, as the table has two rows and therefore two prices.

fxEngine Shell Want this in your own terminal? A standalone version is coming. Get notified.
Loading fxEngine Shell