This gem runs in .
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.- Snowflake
- Databricks
- BigQuery
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 bothRegion 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 asAVG, 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 withDate, 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:
- For Grouping, select the
Citycolumn. - For Pivot, select the
Datecolumn. - Click Fetch unique values, and select
'2025-07-01','2025-07-02','2025-07-03','2025-07-04', and'2025-07-05'. - Select
kWh_Usedas the column containing the values for the new columns. - Select
AVGas the aggregation method.
Result
The output table shows the averagekWh_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.
