Skip to main content

Unpivot Transform

The Unpivot transform allows you to reshape your data from a wide format to a long format, creating new rows from columns. This process is also known as "melting" and is useful for transforming data into a format more suitable for certain types of analysis or visualization.

Basic Usage

To unpivot your data:

  1. Select the Unpivot transform from the transform menu.
  2. Choose the columns you want to keep as identifiers.
  3. Select the columns you want to unpivot into rows.
  4. (Optional) Configure advanced options.

Configuration Options

Basic Options

  • Columns to Keep: Select one or more columns to use as identifiers. These columns will remain unchanged in the output.
  • Columns to Unpivot: Choose the columns that you want to transform into rows. If left unspecified, all columns not selected as "Columns to Keep" will be unpivoted.

Advanced Options

  • Variable Column Name: Specify the name for the new column that will contain the original column names. Default is "variable".
  • Value Column Name: Specify the name for the new column that will contain the values from the unpivoted columns. Default is "value".

Examples

Here's an example of how to use the Unpivot transform:

Example: Unpivoting Monthly Sales Data

Input Dataset:

ProductJanFebMar
Laptop10001200900
Smartphone150016001400
Tablet500450550

Configuration:

  • Columns to Keep: Product
  • Columns to Unpivot: Jan, Feb, Mar
  • Variable Column Name: Month
  • Value Column Name: Sales

Result:

ProductMonthSales
LaptopJan1000
LaptopFeb1200
LaptopMar900
SmartphoneJan1500
SmartphoneFeb1600
SmartphoneMar1400
TabletJan500
TabletFeb450
TabletMar550
tip

Unpivoting is especially useful for analyzing or visualizing data across multiple categories or time periods. It helps prepare your data for time series analysis, boxplots, or other visualizations that require a long format.

caution

Unpivoting will significantly increase the number of rows in your dataset. Be mindful when working with large datasets, as this may impact performance.

Best Practices

  1. Choose Identifiers Wisely: Select columns for "Columns to Keep" that uniquely identify each record in your original dataset.

  2. Consider Column Names: If your unpivoted columns have a meaningful structure (like dates or categories), consider using custom names for the new variable and value columns that reflect this structure.

  3. Handle Missing Data: Be aware that if your original dataset has missing values in the columns being unpivoted, these will be preserved in the unpivoted format.

  4. Preserve Data Types: The unpivot operation will attempt to preserve the data types of your columns. However, if you're unpivoting columns with mixed data types, you may need to handle type conversions after unpivoting.

  5. Preview Results: Always preview the results of your unpivot to ensure the output matches your expectations, especially when working with complex datasets.