Find and Filter the Min or Max Value in Groups in Google Sheets

Published on

This tutorial explains how to find and filter the minimum or maximum value in each group in Google Sheets using a formula or the Filter command.

Use the formula when you want to extract the smallest or largest values for each group into a new range. Use the Filter command when you want to display only the relevant values within the source data.

Find the MIN Values in Groups (Formula Approach)

You might want to find the minimum value in groups with or without a date column. The formula varies depending on the scenario.

Example 1: Finding the Lowest Value in Each Group

Consider the following sample data (A1:B):

Sample data for filtering minimum or maximum values by group

To get the minimum value in each group, use the following QUERY formula:

=QUERY(A1:B, "select Col1, min(Col2) where Col1 is not null group by Col1")

This will return the minimum receipt quantity for each product:

Itemmin Receipt
Product 15
Product 219

How the Formula Works:

  • A1:B -> The data range.
  • Col1 -> The grouping column (adjust it if your grouping column is different, e.g., Col4 for column 4).
  • Col2 -> The column from which to extract the lowest value.

Notes:

  1. Column numbers are relative to the range, not the sheet.
  2. To modify the labels in the result, use the LABEL clause in QUERY.

Example 2: Finding the Lowest Value in Each Group by Date

In certain cases, you may want to find the minimum value in each group based on date, such as tracking the lowest sales per product per day.

Here’s a sample dataset (A1:C):

Sample data for filtering minimum or maximum values by group and date

To find the lowest value per group and date, use:

=QUERY(A1:C, "select Col2, Col1, min(Col3) where Col1 is not null group by Col2, Col1")

Result:

ItemDatemin Receipt
Product 113-Oct-20215
Product 114-Oct-20219
Product 213-Oct-202130
Product 214-Oct-202119

How the Formula Works:

  • A1:C -> The data range.
  • Col2 -> The first column to group by (Item/Category).
  • Col1 -> The date column.

Find the MAX Values in Groups (Formula Approach)

To find the maximum values in each group, replace the min function with max in the formulas.

Example 1: Finding the Largest Value in Each Group

=QUERY(A1:B, "select Col1, max(Col2) where Col1 is not null group by Col1")
Itemmax Receipt
Product 120
Product 231

Example 2: Finding the Largest Value in Each Group by Date

=QUERY(A1:C, "select Col2, Col1, max(Col3) where Col1 is not null group by Col2, Col1")
ItemDatemax Receipt
Product 113-Oct-202120
Product 114-Oct-202110
Product 213-Oct-202131
Product 214-Oct-202125

Find the MIN or MAX Values Using the Filter Command

Filtering the source data directly has two advantages:

  1. You can see and edit the results in the original range.
  2. You avoid creating additional ranges, keeping your sheet clean.

To filter the min or max values by group, apply the filter function to the numeric column.

Example 1: Filtering the Smallest Value in Each Group

We will use the same two-column dataset, where Item is in column A and Receipt in column B.

Steps:

  1. Select B1:B.
  2. Click Data > Create a Filter.
  3. Click the filter drop-down in B1.
  4. Select Filter by condition > Custom formula is.
  5. Enter the formula:
    =B2=MINIFS($B$2:B, $A$2:$A, A2)
    Example of finding the minimum value in each group using the Filter menu
  6. Click OK.

This filters the smallest values in each group.

How the Formula Works:

MINIFS($B$2:B, $A$2:$A, A2)
  • MINIFS finds the smallest value in B2:B, where A2:A matches the item in A2.
  • This applies to each row as A2 updates to A3, A4, and so on within the filter range.

=B2 checks whether each row’s value matches the minimum value in its group. If it does, the row is included in the filter.

Example 2: Filtering the Largest Value in Each Group

To filter the maximum value instead, use:

=B2=MAXIFS($B$2:B, $A$2:$A, A2)

Example 3: Filtering the Smallest Value in Each Group by Date

If dates are in column A, items in column B, and receipt quantities in column C, use:

  1. Select C1:C.
  2. Click Data > Create Filter.
  3. Click the filter drop-down in C1.
  4. Select Filter by condition > Custom formula is.
  5. Enter:
    =C2=MINIFS($C$2:C, $A$2:$A, A2, $B$2:$B, B2)
  6. Click OK.

This filters the smallest values in each group by date and category.

Filter menu to filter the minimum value by category and date

How the Formula Works:

  • MINIFS($C$2:C, $A$2:$A, A2, $B$2:$B, B2) finds the minimum value in C2:C where A2:A = A2 and B2:B = B2.
  • If C2 matches this minimum, the row is shown in the filter.

This applies to each row in the range.

Example 4: Filtering the Largest Value in Each Group by Date

Simply replace MINIFS with MAXIFS:

=C2=MAXIFS($C$2:C, $A$2:$A, A2, $B$2:$B, B2)

FAQs

Does the formula update when new data is added?

Yes, since we use open-ended ranges, the formula captures new values dynamically.

Does the filter menu refresh automatically when new values are added?

No, you must click the filter drop-down and select OK to refresh the filtered data.

Prashanth KV
Prashanth KV
Your Trusted Google Sheets and Excel Guide Prashanth KV brings a wealth of experience in Google Sheets and Excel, cultivated through years of work with multinational corporations in Mumbai and Dubai. As a recognized Google Product Expert in Docs Editors, Prashanth shares his expertise through insightful blogging since 2012. Explore his blog for practical tips and guidance on maximizing your spreadsheet skills.

Filter Top N per Category in Excel (Using FILTER & COUNTIFS)

You can use a combination of FILTER and COUNTIFS to filter the top N...

Rank per Group in Excel

You have two groups of 20 students each. How do you determine the rank...

Real-Time Excel Filtering Using Combo Box & FILTER Function

In this tutorial, you’ll learn how to set up real-time Excel filtering using a...

Google Sheets: Extract Top N per Group from Query Aggregation

When working with grouped and aggregated data in Google Sheets, you might need to...

More like this

Google Sheets: Extract Top N per Group from Query Aggregation

When working with grouped and aggregated data in Google Sheets, you might need to...

How to Extract Top N from Aggregated Query Results in Google Sheets

To summarize data in Google Sheets, you can use the QUERY function. However, if...

How to Use RANK IF in Google Sheets (Conditional Ranking)

You can use the RANK function to rank values in an entire dataset. But...

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.