ADDCOLUMN & ADDROW
Add columns or rows to a table to expand your dataset — append new metrics to sales data, insert historical records, or build tables dynamically from user input. Both functions create new tables without modifying the original.
Syntax
ADDCOLUMN
ADDCOLUMN(table, column, [index])table (Table | Array): The source table or array-of-arrays
column (Array): Array of values for the new column. If shorter than the table's row count, remaining cells will be empty
index (Number, optional): Zero-based position to insert the column. Defaults to end (append)
ADDROW
ADDROW(table, row, [index])table (Table | Array): The source table or array-of-arrays
row (Array): Array of values for the new row, matching the table's column count
index (Number, optional): Zero-based position to insert the row. Defaults to end (append)
Returns: Table – A new table with the added column or row.
Both functions use zero-based indexing. Index 0 inserts at the beginning, index 1 after the first item, etc. Omit the index to append to the end.
Examples
Add profit margin column to sales data
Calculate margins for each product and add them as a new column:
SALES_TABLE := TABLE(
ARRAY("Laptop", 1200, 950),
ARRAY("Mouse", 45, 12),
ARRAY("Keyboard", 89, 34)
)
PROFIT_MARGINS := MAP(SALES_TABLE, function(ROW: ROW[1] - ROW[2]))
SALES_WITH_MARGIN := ADDCOLUMN(SALES_TABLE, PROFIT_MARGINS)Creates a 4-column table with product name, price, cost, and calculated profit margin.
Insert a priority column at the start
Add priority flags as the first column in a task list:
PRIORITIES := ARRAY("High", "Medium", "Low", "High")
UPDATED_TASKS := ADDCOLUMN(TASK_TABLE, PRIORITIES, 0)The priority column appears first (index 0), shifting existing columns to the right.
Append a new customer row
Add a new customer to the end of your customer table:
NEW_CUSTOMER := ARRAY("Alice Chen", "[email protected]", "Premium")
CUSTOMERS_UPDATED := ADDROW(CUSTOMER_TABLE, NEW_CUSTOMER)Appends the new customer as the last row.
Insert historical data at specific position
Add Q1 data at the beginning of a quarterly report:
Q1_DATA := ARRAY("Q1", 125000, 98000, 27000)
FULL_REPORT := ADDROW(QUARTERLY_REPORT, Q1_DATA, 0)Inserts Q1 as the first row, pushing existing quarters down.
Build a table dynamically
Construct a comparison table from separate data sources:
BASE_TABLE := TABLE(ARRAY("Plan A", 29), ARRAY("Plan B", 49))
WITH_FEATURES := ADDCOLUMN(BASE_TABLE, ARRAY(10, 25))
WITH_USERS := ADDCOLUMN(WITH_FEATURES, ARRAY(100, 500))
FINAL_TABLE := ADDROW(WITH_USERS, ARRAY("Plan C", 99, 50, 2000))Builds a pricing comparison table one column and row at a time.
Common mistakes
Column length mismatch —
ADDCOLUMNaccepts arrays shorter than the table (fills with empty cells), butADDROWexpects the array to match the column countForgetting zero-based indexing — Index 1 inserts after the first item, not at the first position. Use 0 for the beginning
Modifying original table — Both functions return new tables. Assign the result to a variable:
NEW_TABLE := ADDCOLUMN(...)Using negative indexes — Indexes must be 0 or greater. Use omit the index parameter to append to the end
ADDROW requires the new row array to match the table's column count. Mismatched lengths will cause errors.
When to use alternatives
Building tables from scratch: Use TABLE to define all rows at once rather than adding them one by one
Removing columns or rows: Use REMOVECOLUMN or array slicing with FILTER
Modifying existing values: Use MAP to transform existing cells rather than adding new ones
Related functions
TABLEFILTER · MAP · ARRAY · TABLE · REMOVECOLUMN · FILTER