Skip to main content

Pivot Transform

The Pivot transform allows you to reshape your data from a long format to a wide format by creating new columns based on unique values in a specified column. This is useful for summarizing and analyzing data in a more compact and readable format.

Basic Usage

To pivot your data:

  1. Select the Pivot transform from the transform menu.
  2. Choose the columns by which to group your rows.
  3. Select the column to create new headers from.
  4. Specify the column containing values for the new columns.
  5. (Optional) Configure any advanced options.

Configuration Options

Basic Options

  • Group Rows By: Select one or more columns to use as the index for your pivoted data.
  • Create New Columns From: Choose the column whose unique values will become new column headers.
  • Values for New Columns: Select the column containing the data that will populate the new columns.

Advanced Options

  • Aggregation Method: Choose how to aggregate values when they fall into the same pivoted cell. Available options include:

    • Sum
    • Mean
    • Count
    • Min
    • Max
    • (And more, depending on the data type)
  • Fill Value: Specify a value to fill empty cells after pivoting.

Examples

Here are some examples demonstrating how to use the Pivot transform:

Example 1: Basic Pivot

Input Dataset:

DateStoreProductSales
2024-09-01Store AProduct 1100
2024-09-01Store AProduct 2150
2024-09-02Store BProduct 190
2024-09-02Store BProduct 2130

Configuration:

  • Group Rows By: Store
  • Create New Columns From: Product
  • Values for New Columns: Sales
  • Aggregation Method: Sum
  • Fill Value: 0

Result:

StoreProduct 1Product 2
Store A100150
Store B90130
Example 2: Multi-Index Pivot

Input Dataset:

DateStoreProductSales
2024-09-01Store AProduct 1100
2024-09-01Store AProduct 2150
2024-09-02Store BProduct 190
2024-09-02Store BProduct 2130
2024-09-03Store AProduct 1120

Configuration:

  • Group Rows By: Date, Store
  • Create New Columns From: Product
  • Values for New Columns: Sales
  • Aggregation Method: Sum
  • Fill Value: 0

Result:

DateStoreProduct 1Product 2
2024-09-01Store A100150
2024-09-02Store B90130
2024-09-03Store A1200
tip

When pivoting data with multiple entries for the same combination of index and column values, make sure to choose an appropriate aggregation method to combine the values.

caution

Pivoting can significantly increase the number of columns in your dataset, especially if the "Create New Columns From" field has many unique values. This may impact performance and readability for very large datasets.

Best Practices

  1. Choose Meaningful Indexes: Select columns for "Group Rows By" that provide a useful structure for the pivoted data.

  2. Consider Data Types: The aggregation methods available may depend on the data type of the "Values for New Columns" field. Choose a method that fits your data.

  3. Handle Missing Data: Use the "Fill Value" option to handle empty cells after pivoting (e.g., 0 for numerical data, "Unknown" for categorical data).

  4. Limit New Columns: To keep your pivoted data manageable, limit the number of unique values in the "Create New Columns From" field.

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