WorkbookLogic
FormulaFreeStructureadvancedFILTERLARGESORTMINCOUNTIFIFAND

Return the Top N Values Within a Group

By WorkbookLogic

Return the highest-scoring records within a selected group by calculating a group-specific cutoff, filtering complete source rows, and sorting the dynamic result in descending order.

ExcelLast reviewed Sep 11, 2026
filter-on-top-n-values-with-criteria-v1.0.0.xlsxFree
FILTER on Top N Values with Criteria, Formula Review
Build a group-specific cutoff, filter complete records, then sort the spill by score.
Local source dataInputs and thresholdSorted filtered result
NameGroupScoreControlValueNameGroupScore
NoahB65Selected groupBMasonB88
LiamB80Top N3AnnieB86
MasonB88Group count6CassidyB83
AvaB76Nth threshold83
AnnieB86
CassidyB83
Representative formula
=SORT(FILTER(data,(score>=LARGE(IF(group=selected_group,score),MIN(n,COUNTIF(group,selected_group))))*(group=selected_group)),3,-1)

Overview

Return complete rows for the highest scores inside one selected group. A helper formula calculates the group-specific Nth-highest cutoff; a dynamic-array formula filters qualifying rows and sorts them from highest to lowest score.

When to use it

Use it for top performers within a team, largest exceptions within a category, highest-value opportunities by region, or a compact dashboard ranking. It fits normalized row data with one group and numeric score per record.

When not to use it

Use SORT plus TAKE when the output must contain exactly N rows and a deterministic tie-break rule exists. Use a PivotTable value filter for an interactive report, or plain FILTER when the threshold is fixed rather than rank-based. A reusable ranking subsystem with several measures belongs in a Block.

Problem

Taking the largest scores from the full dataset can return records from the wrong group. Filtering first but leaving the result in source order does not create a ranking. The cutoff must be calculated from the selected group, then applied to complete source rows and sorted.

Inputs

Input

Location

Sample

Selected group

Combined Example!F12

B

Top N

Combined Example!F13

3

Source data

The synthetic data in Combined Example!A12:C23 contains Name, Group, and numeric Score. Group B has:

Name

Group

Score

Reid

B

65

Avery

B

80

Mason

B

88

Jordan

B

76

Annie

B

86

Cassidy

B

83

Each row is one record. Sorting the source is unnecessary because the output is sorted separately. Duplicate scores are allowed and can create ties. Blank or nonnumeric scores should be cleaned or excluded before ranking.

Calculations

  1. Count records belonging to the selected group.
  2. Cap N at that qualifying count.
  3. Filter the score column to the selected group.
  4. Use LARGE to find the capped Nth-highest score.
  5. Filter complete rows by both group and cutoff.
  6. Sort the returned rows by Score descending.

Outputs

With Group B and N = 3, the cutoff is 83. The spilled result contains Mason at 88, Annie at 86, and Cassidy at 83, ordered from highest to lowest. The output has three columns and as many rows as meet the cutoff.

Formula map

Group-specific cutoff

=LARGE(FILTER(C12:C23,B12:B23=F12),MIN(F13,COUNTIF(B12:B23,F12)))

Filtered and sorted records

=SORT(FILTER(A12:C23,(C12:C23>=F14)*(B12:B23=F12),"No data"),3,-1)

Enter the second formula once at H12. Multiplication implements AND logic, and 3,-1 sorts by the third returned column descending.

Model checks

The workbook tests that every returned row belongs to Group B and meets the 83-point cutoff. It also checks that the returned count equals the smaller of N and available rows for the supplied no-tie example. Passing tests return OK.

Edge cases

  • If N exceeds the group count, MIN caps the requested rank at the available number of rows.
  • If the selected group has no records, the cutoff helper can error before the outer FILTER returns No data.
  • Ties at the cutoff can return more than N rows because the test is >=.
  • Occupied destination cells produce #SPILL!.
  • Zero, negative, noninteger, or nonnumeric N values require input validation.
  • Nonnumeric scores should be removed or handled explicitly before LARGE.

Common errors

  • Ranking all groups: the cutoff comes from the wrong population. Filter the score array before LARGE.
  • Assuming FILTER ranks results: FILTER preserves source order. Wrap it in SORT.
  • Expecting exactly N rows with ties: a cutoff includes every equal score. Define a tie-break and use SORT plus TAKE when exact row count matters.

Example

Group B scores are 65, 80, 88, 76, 86, and 83. The third-largest value is 83. Filtering for Group B scores at least 83 returns 88, 86, and 83; sorting descending produces Mason, Annie, and Cassidy in that order.

Example workbook

Replace the cream group and N controls in Combined Example!F12:F13 or edit source rows in A12:C23. The cutoff appears in F14, and the live result spills from H12. Formula Review isolates the qualifying count, cutoff, and ranked output.

Key takeaway

Calculate the ranking threshold inside the selected group before filtering complete rows, and define tie behavior explicitly when the output must contain exactly N records.