Shape · Summarize and reshape
Pivot
Turns the values of one column into new columns, such as one row per store with a column per month. The reverse of Unpivot.
Also known as: Cross tab, long to wide
How it works
Choose the columns to Keep as rows (id columns), the column to Spread into columns from and the column the Values from. Each distinct value of the spread column becomes a column, filled with Aggregate with: Sum (the default), Count, Average, Min, Max, Median, Std dev, Count distinct, Concatenate, which joins the values with the Separator (, by default), or First. Concatenate and First take the values in the order rows arrive. With no id columns the rows are grouped by every remaining column. A combination with no rows gives a null cell. Unpivot does the reverse.
Inputs and outputs
Inputs
data— Table
Outputs
data— Table
Settings
The Attributes panel of Pivot, as in the app: the controls work, but nothing runs — there is no data behind it.
The same settings, as the Assistant writes them
{
idColumns: string[]
nameColumn: string
valueColumn: string
aggFunc: "SUM"|"COUNT"|"AVG"|"MIN"|"MAX"|"MEDIAN"|"STDDEV"|"COUNT_DISTINCT"|"CONCAT"|"FIRST"
separator?: string (CONCAT only, default ",")
}
Example
Monthly sales rows should become one line per store. Keep store as rows, spread from month, take values from sales and aggregate with Sum.
| store | Jan | Feb | Mar |
|---|---|---|---|
| Downtown | 120 | 95 | 130 |
| Airport | 80 | NULL | 90 |