Edilitics | Data to Decisions

Group By

Group rows by one or more columns and apply aggregations like sum, count, mean, median, min, max, mode, first, last, variance, and standard deviation.

Group By collapses your dataset into one row per unique value (or unique combination of values, when grouping by more than one column) and computes aggregations across the remaining columns. The output is a summary table, not the original rows with new columns added. Every operation downstream works on the grouped result.

You can apply multiple aggregations to the same column (for example, both sum and mean on revenue) by adding extra aggregation rows in one operation.

Group By reshapes the entire dataset. All original rows are replaced by the grouped summary. If you need to keep original rows, add a Conditional Column or Column Aggregation instead.


When to Use Group By

  • Revenue by region. Group by region, sum revenue to get total sales per territory.
  • Revenue by region and tier. Group by region and product_tier together to get total sales per territory, broken down by subscription tier.
  • Order count by product tier. Group by product_tier, count order_id to see volume per segment.
  • Average deal size by sales rep. Group by sales_rep, take the mean of revenue.
  • Distinct customer count per region. Group by region, count distinct customer_name.
  • Spread analysis. Group by product_tier, compute std dev of revenue to understand deal size variability per tier.

Sample Dataset

The examples in this doc use the Edilitics sample orders dataset. Download it to follow along in your own workspace.

edilitics_sample_orders.csv

Sample orders dataset for hands-on practice · 500 rows

Download

Relevant columns for Group By examples:

Prop

Type


Aggregations by Column Type

The aggregation options shown depend on the type of the column being aggregated.

Numerical columns:

AggregationLabelWhat it computes
SumSumTotal of all values in the group
CountCountNumber of non-null rows in the group
Count DistinctCount DistNumber of unique non-null values
MinimumMinLowest value in the group
MaximumMaxHighest value in the group
MeanMeanArithmetic average
MedianMedianMiddle value when sorted
ModeModeMost frequently occurring value
FirstFirstFirst value in the group's row order
LastLastLast value in the group's row order
Variance (sample)Var (Sample)Sample variance (ddof=1)
Variance (population)Var (Pop)Population variance (ddof=0)
Std Dev (sample)Std Dev (Sample)Sample standard deviation (ddof=1)
Std Dev (population)Std Dev (Pop)Population standard deviation (ddof=0)

Categorical (string) columns:

AggregationLabelWhat it computes
CountCountNumber of non-null rows in the group
Count DistinctCount DistNumber of unique non-null values
ModeModeMost frequently occurring value
FirstFirstFirst value in the group's row order
LastLastLast value in the group's row order

Min and Max are not offered for categorical columns: they would compute lexicographic (alphabetical) ordering on the text, which is meaningless or misleading for plain category values (alphabetically, "Blue" comes before "Green" before "Red", but that ordering carries no real-world meaning).

Datetime, date, and time columns:

AggregationLabelWhat it computes
CountCountNumber of non-null rows in the group
Count DistinctCount DistNumber of unique non-null values
MinimumMinEarliest timestamp in the group
MaximumMaxLatest timestamp in the group
FirstFirstFirst value in the group's row order
LastLastLast value in the group's row order

Mean, median, sum, variance, and standard deviation are not offered for datetime columns.

Use Sample variance/std dev when your dataset is a sample drawn from a larger population (the typical case for order data). Use Population when your dataset is the complete population.


How to Apply Group By

Open the Group By operation

In your Transform pipeline, click Add Operation and select Group By from the operation list.

If your dataset has columns with Object, List, or dictionary types, a warning appears. Flatten those columns first to avoid data loss.

Select the Group By column(s)

Choose one or more columns from the dropdown to group by. All column types are available: string, datetime, and numerical. Object and list columns are excluded.

In the sample dataset, try region alone to group orders by territory, or region and product_tier together to group by territory and subscription segment combined. Selecting more than one column produces one output row per unique combination of values across all of them, not one row per column.

Once at least one column is selected, three column headers appear: Aggregate Column, Aggregation, and Result Column Name.

Review and adjust aggregations

All remaining columns (every column not selected as a group-by key) appear automatically with default aggregations:

  • Numerical columns default to Sum
  • Categorical and datetime columns default to Count

The Result Column Name is auto-generated as sum_revenue, count_order_id, etc. Edit any name to something more meaningful.

Change the aggregation for any column using its Aggregation dropdown. Only aggregations valid for that column's type appear (see Aggregations by Column Type).

Remove a column from the output using its remove icon, if you do not need its aggregated value in the result.

Add extra aggregations (optional)

Click Add Column to add a blank aggregation row. Use this to apply a second aggregation to any column, for example mean_revenue alongside sum_revenue.

Each added row needs: an Aggregate Column, an Aggregation, and a unique Result Column Name.

The same aggregation cannot be applied to the same column twice. Already-used aggregations are hidden from the dropdown for that column.

Click Save & Preview

Click Save & Preview. Edilitics applies the group by and aggregations. The success toast confirms: "Group By applied. Preview now reflects grouped and aggregated output."

The preview now shows the grouped summary table, one row per unique group-by value or combination.

Verify in the preview

Check row count. It should equal the number of distinct values (or distinct combinations, for a multi-column group-by) in the group-by selection. Check aggregated values for sense. Nulls in aggregated columns indicate the group had no non-null values for that column.


Before and After

Group By columns: region, product_tier. Aggregations: sum of revenue, count of order_id.

Input (500 rows):

order_idregionproduct_tierrevenue
ORD-2024-0001North AmericaEnterprise12450.00
ORD-2024-0047EuropeGrowth8320.50
ORD-2024-0099North AmericaEnterprise83841.00
ORD-2024-0312North AmericaGrowth3750.75
............

Output (one row per region + product_tier combination):

regionproduct_tiersum_revenuecount_order_id
North AmericaEnterprise421430.5041
North AmericaGrowth156210.0033
EuropeGrowth284210.7544
EuropeEnterprise198340.0022
............

500 rows collapsed to one row per (region, product_tier) pair. All original columns except region and product_tier are replaced by the aggregated columns.


Code Equivalent

-- Compatible with PostgreSQL, BigQuery, Snowflake, Redshift, DuckDB
SELECT
  region,
  product_tier,
  SUM(revenue)          AS sum_revenue,
  COUNT(order_id)       AS count_order_id
FROM orders
GROUP BY region, product_tier;
import polars as pl

df = df.group_by(["region", "product_tier"]).agg([
    pl.col("revenue").sum().alias("sum_revenue"),
    pl.col("order_id").count().alias("count_order_id"),
])

After Save & Preview, the pipeline shows a DQ delta badge on this step - green if the table score improved, red if it dropped. See Data Quality Scoring for how scores are calculated.


Operation Reference

Prop

Type


Frequently Asked Questions


Next Steps

Need help? Email support@edilitics.com with your workspace, job ID, and context. We reply within one business day.

Last updated on

On this page