Unpivot
The Unpivot processor uses the Snowflake Unpivot function to rotate a table, converting the specified columns into rows. You can use this processor to convert a wide table into a narrower table.
When you configure the Unpivot processor, you indicate how to define the columns to unpivot. You can specify column names, strings included in the column names, or regular expressions that match the column names. You define a name for the new column that contains the names of the rotated columns, and a name for the new column that contains the values from the rotated columns.
The resulting data includes a separate row for each matching column.
For more information about the Snowflake Unpivot function, see the Snowflake documentation.
Example
Say you have a quarterly_sales table with the following data:
| DEPT_ID | DEPT | Q1 | Q2 | Q3 | Q4 |
|---|---|---|---|---|---|
| 1 | tools | 355 | 420 | 486 | 433 |
| 2 | housewares | 1088 | 980 | 866 | 945 |
| 3 | garden | 280 | 340 | 364 | 328 |
- Column Match Criteria property: Column Name
- Columns property:
Q1,Q2,Q3,Q4 - New Name Column property:
QUARTER - New Value Column property:
UNIT_SALES
| DEPT_ID | DEPT | QUARTER | UNIT_SALES |
|---|---|---|---|
| 1 | tools | Q1 | 355 |
| 1 | tools | Q2 | 420 |
| 1 | tools | Q3 | 486 |
| 1 | tools | Q4 | 433 |
| 2 | housewares | Q1 | 1088 |
| 2 | housewares | Q2 | 980 |
| 2 | housewares | Q3 | 866 |
| 2 | housewares | Q4 | 945 |
| 3 | garden | Q1 | 280 |
| 3 | garden | Q2 | 340 |
| 3 | garden | Q3 | 364 |
| 3 | garden | Q4 | 328 |
Notice how the columns defined in the Columns property appear in the
QUARTER column, and the value for each of the columns appears
in the UNIT_SALES column. Also, each row from the original table
generates four rows when unpivoted, one for each quarter.
Configuring an Unpivot Processor
Configure an Unpivot processor to rotate a table by converting specified columns into rows.