User GuidesAPI ReferenceRelease Notes
Doc HomeHelp CenterLog In
User Guides

Unpivot Option

Use Unpivot to change the shape of a table.

UNPIVOT reorganizes the structure of the table by taking related columns of data and moving them into different rows.
UNPIVOT follows these rules:

  • It creates new columns as they are defined in the operation. Tamr creates primary keys for them. See Primary Key Management. If no value is defined for a column, then it is null.
  • Carries over all columns that are not mentioned in its definition. Specifically, UNPIVOT carries over all columns except for the columns that you explicitly mention in an expression and the columns created by the expressions. To keep some columns at the left side of the table, such as table keys, mention them explicitly in the UNPIVOT definition.

Example

In the following example, the input datasets have an attribute for spend each quarter. You can use Unpivot to reorganize this table and change these four attributes into two: one attribute for the quarter in which the spend occurred, and another attribute for the amount of spend.

1708

Before unpivot, the customer was represented by one record in the dataset, and each quarter of spend was one column.

In this example, we create the attribute labeled Quarter with the header from each of the attributes Q1, Q2, Q3, and Q4. The Spend attribute is filled with values from the corresponding quarter.

786 750

The result is that Quarter and Spend are filled with the information from the original dataset. The columns from which the data was extracted are emptied. Any other unified attributes are preserved for each record. Because we use UNPIVOT for the attributes, this example results in the number of records that is four times the number of records in each of the input datasets.

1702

The customer is now represented by four records.

Unpivoting Additional Attributes

When you need to unpivot multiple attributes together, you can add dependent columns. One common use case is when the variable attribute contains data that have different units. In this case, you can add the units column as a dependent column.

520

To add a dependent column:

  1. Choose add dependent column and select Unified Attributes from a dropdown menu.
  2. Drag and drop the dependent column from the list at the left to its corresponding attribute on the right. In our example, the attribute containing unit information (VSTEMP_U) is the dependent column.
1177

Here is an example of how it works. To see it, choose the information icon:

581

Note: You can also include an UNPIVOT statement in a transformation script. See Unpivot.