Get Top N% Scores Per Group in Google Sheets (Dynamic Filtering)

When analyzing data in Google Sheets, you often need to get the top N% scores per group dynamically. This technique is useful for various scenarios, such as:

  • Identifying top customers based on purchases
  • Analyzing best-selling products within each category
  • Selecting top-performing employees or students
  • Targeting marketing campaigns at high-value segments

In this guide, we’ll explore how to use Google Sheets functions like FILTER and PERCENTILE to efficiently extract the top N% values per group. We’ll also cover a method to accomplish this without a helper column for a more streamlined approach.

Example: Identifying the Top 20% of Best-Selling Products by Category

Sample Data

We’ll use the following dataset, which contains product names, categories, and units sold:

Sample Dataset – Product names, categories, and units sold

Our goal is to get the top 20% scores per group, meaning we will determine the 80th percentile within each category and include all products that meet or exceed that threshold.

📋 To make it easier to practice, click here to make a copy of the sample Google Sheet and follow along with the steps in real time.

Step 1: Find the Nth Percentile Per Group

To determine the top N% threshold within each group, we use the PERCENTILE function, which finds the value above which the top N% of data points fall.

Formula to Calculate the 80th Percentile Per Group

Enter the following formula in cell D2 and drag it down for all rows:

=PERCENTILE(FILTER($C$2:$C, $B$2:$B=B2), 80%)
Applying Formula – Drag-down PERCENTILE function per group

How It Works:

  • FILTER($C$2:$C, $B$2:$B=B2): Extracts only the sales numbers for the current row’s category.
  • PERCENTILE(..., 80%): Returns the 80th percentile (the threshold for the top 20%).
  • Dragging this formula down ensures each row has the correct percentile value for its category.

After applying this formula, column D will contain the 80th percentile value for each group.

Step 2: Filter Values Greater Than or Equal to the Nth Percentile

Now that we have the percentile threshold for each group, we can filter products that meet or exceed this value.

Formula to Filter the Top N% Values

Enter the following formula in cell F2:

=FILTER(A2:C, C2:C>=D2:D)

Explanation:

  • FILTER(A2:C, C2:C>=D2:D):
    • Filters product names, categories, and units sold (columns A to C).
    • Includes only rows where Units Sold (column C) is greater than or equal to the percentile value in column D.

Expected Output

After applying this filter, you will see only the top 20% of products in each category based on sales.

Final Result – Filtered top N% values per group

Alternative: Get the Top N% Scores Per Group Without a Helper Column

If you want a more efficient formula that doesn’t require a helper column, you can use the MAP and LAMBDA functions (available in Google Sheets).

Formula to Calculate Percentile On-the-Fly

Clear any previous formulas in column D and enter the following formula in cell D2. There’s no need to drag it down, as it automatically expands to cover all rows.

=MAP(B2:B, LAMBDA(row, PERCENTILE(FILTER($C$2:$C, $B$2:$B=row), 80%)))

How It Works:

  • MAP(B2:B, LAMBDA(row, ...)): Iterates over each row’s category.
  • FILTER($C$2:$C, $B$2:$B=row): Extracts sales for that category.
  • PERCENTILE(..., 80%): Finds the 80th percentile for that category.

Directly Use This in FILTER Formula

Instead of using a separate helper column, you can embed this formula directly inside the FILTER function:

=FILTER(A2:C, C2:C >= MAP(B2:B, LAMBDA(row, PERCENTILE(FILTER($C$2:$C, $B$2:$B=row), 80%))))

Why This Method Is Better

This approach eliminates the need for extra columns, making your spreadsheet cleaner and more efficient. The formula is more streamlined, reducing manual work and improving readability. Additionally, it dynamically adjusts for all groups, ensuring accurate percentile calculations without requiring modifications for different datasets.

Conclusion

By following these methods, you can efficiently get the top N% scores per group in Google Sheets. Whether you choose to use a helper column or an inline formula, both approaches allow you to dynamically filter and analyze top-performing values.

This technique is highly versatile and can be applied to:

  • Sales analysis (top-selling products per category)
  • Marketing insights (top-spending customers per segment)
  • Education tracking (top-scoring students per subject)

By leveraging the FILTER and PERCENTILE functions, you can automate complex data filtering in Google Sheets with ease!

Additional Resources

For further learning, check out these related guides:

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.

Count Consecutive Duplicates in Excel (Dynamic Array Formula)

Counting consecutive duplicates in Excel is useful for analyzing patterns, detecting repetitive sequences, and...

How to Break RANK Ties Alphabetically in Google Sheets

The RANK function in Google Sheets is commonly used to assign rankings to numerical...

Google Sheets: Highlight an Entire Column If Any Cell Has an Error

Google Sheets allows you to highlight an entire column if any cell has an...

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

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

More like this

How to Break RANK Ties Alphabetically in Google Sheets

The RANK function in Google Sheets is commonly used to assign rankings to numerical...

Google Sheets: Highlight an Entire Column If Any Cell Has an Error

Google Sheets allows you to highlight an entire column if any cell has an...

Google Sheets: Extract Top N per Group from Query Aggregation

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

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.