Skip to main content
This gem runs in .
Use the Pivot gem to convert your table from long format to wide format. You select a column whose unique values become new columns in the output, making it easier to summarize and compare categories side by side. Each unique value that you select from the pivot column creates a new column in the result.

Input and output

The Pivot gem uses the following input and output ports.

Parameters

Configure the Pivot gem using the parameters for your SQL warehouse.

Grouping

Select one or more columns to group your data before applying the aggregation. You can also change the grouping column name in the output.For example, to analyze sales data by region and product category, select both Region and Product_Category as grouping columns.

Pivot

Choose a pivot column that contains the unique values that will become new columns in the output table.After you select the column, click Fetch unique values to retrieve all distinct values from that column. Select the values that you want to transform into new columns.

Aggregation

Choose a column containing the data values that will populate the cells of the new pivot columns. The values are aggregated and placed at the intersection of each group and pivot column combination.Choose an aggregation method such as AVG, SUM, COUNT, MIN, or MAX.You cannot define a column alias for the aggregation in Snowflake.

Example: Energy consumption

Imagine you have a dataset of energy consumption with Date, City, and kWh_Used for different buildings, and you want to see the average kWh_Used per city for specific dates, with dates as columns. You start with the following data:
In the Pivot gem configuration:
  1. For Grouping, select the City column.
  2. For Pivot, select the Date column.
  3. Click Fetch unique values, and select '2025-07-01', '2025-07-02', '2025-07-03', '2025-07-04', and '2025-07-05'.
  4. Select kWh_Used as the column containing the values for the new columns.
  5. Select AVG as the aggregation method.

Result

The output table shows the average kWh_Used for each city on the specified dates, with the dates as new columns. Some cells are null because there is no corresponding data for certain combinations of City and Date in the input table. The Pivot gem turns the selected Date values into columns and populates them with aggregated kWh_Used values for each City. For example, Chicago has no data for 2025-07-01, so its value for that date is null. A null value therefore indicates that the input dataset contains no data for that city and date combination.