Highlight Largest 3 Values in Each Row in Google Sheets (Handles Ties!)

Published on

I’ll deviate from traditional approaches to highlight the largest 3 (or N) values in each row in Google Sheets. The common methods using LARGE and RANK have unpredictable issues that can lead to incorrect results. What are they?

The Problem with Traditional Methods

We usually use the LARGE function to find the nth largest value. In conditional formatting, it helps highlight the top 3 values in a row. However, this approach has some issues:

  1. Empty Cells Cause Errors: If most of the row’s cells are empty, LARGE may return a #NUM! error. To fix this, you can use the N function to return 0 for empty cells. But improper usage can lead to incorrect highlighting.
  2. Ties in the Top 3: The RANK function (or LARGE + N) is often preferred to handle ties. However, it automatically includes all occurrences of the nth largest value. This means if multiple values tie for the third-highest spot, all of them will be highlighted, exceeding the limit of 3 highlights.

Example: Unexpected Extra Highlights Due to Ties

Assume a row contains the numbers: 30, 20, 20, 20, 10, 10, 5. The third-largest value is 20, but because there are three occurrences of 20, all of them get highlighted.

Score3020202010105
Rank1222557

This means the top 3 + all duplicates of the 3rd value get highlighted, not just the top 3. So, handling ties properly is crucial when you highlight the largest 3 values in each row.

4 Approaches to Highlight the Largest 3 Values in Each Row

To handle ties effectively, I’ve developed four formulas to highlight the top 3 values in each row. Choose the one that best fits your needs:

Values1. Top 3 (Exactly 3, No Extra Ties)2. Top 3 + All Duplicates of Nth3. Top 3 (Distinct Values Only)4. Top 3 (Distinct Values + All Occurrences)
30
20
20☑️
20☑️☑️
10
10☑️
5

How These Methods Differ:

  • First & Third Methods: Highlight exactly 3 values (first method includes ties, third method ensures uniqueness).
  • Second Method: Highlights top 3 including duplicates of the nth value.
  • Fourth Method: Highlights top 3 distinct values + all occurrences of those values (duplicates in a separate color for clarity).

Example Formulas for Highlighting Top 3 in Each Row

1. Top 3 (Exactly 3, No Extra Ties)

This formula highlights exactly 3 values, ignoring extra ties:

=AND(B2<>"", XMATCH(CELL("ADDRESS", B2), SORTN(TOCOL(ADDRESS(ROW($B2:$K2), COLUMN($B2:$K2))), 3, 0, TOCOL($B2:$K2), FALSE)))
Google Sheets highlighting exactly the top 3 values in each row, ignoring extra ties

Steps to Apply in Google Sheets:

  1. Select the range where you want to apply the rule (e.g., B2:K7).
  2. Click Format > Conditional formatting.
  3. In the Format Rules section, select Custom formula is.
  4. Enter the formula.
  5. Choose a formatting style (e.g., bold text, background color).
  6. Click Done.

How It Works:

  • SORTN selects the address of the top 3 largest values in each row.
  • XMATCH checks if each cell’s address appears in the sorted list.
  • B2<>"" ensures that empty cells are ignored.

2. Top 3 + All Duplicates of Nth

This formula highlights top 3 + all duplicates of the 3rd value:

=RANK(B2, $B2:$K2)<=3
Google Sheets highlighting the top 3 values in each row, including all duplicates of the 3rd largest value
  • How It Works: If a number ranks ≤3, it gets highlighted, including all duplicates of the 3rd highest value.

3. Top 3 (Distinct Values Only)

To highlight only 3 unique top values:

=AND(XMATCH(B2, SORTN(TOCOL($B2:$K2, 3), 3, 2, 1, FALSE)), COUNTIF($B2:B2, B2)<2)
Google Sheets highlighting only the 3 largest unique values in each row, ignoring duplicates
  • XMATCH matches each value in the top 3 largest unique values returned by SORTN.
  • COUNTIF ensures only the first occurrence of each value is highlighted.

4. Top 3 (Distinct Values + All Occurrences)

To highlight top 3 unique values and all duplicates separately:

=XMATCH(B2, SORTN(TOCOL($B2:$K2, 3), 3, 2, 1, FALSE))
Google Sheets highlighting the top 3 unique values in each row along with all their duplicates in a separate color
  • Use this rule as a second rule alongside the previous one and apply a different color to distinguish duplicates.
    Google Sheets highlighting tied values in a different color for better distinction
  • This formula is the same as the previous one except it does not use COUNTIF, meaning it highlights all occurrences of the top 3 unique values instead of just the first.

Real-Life Applications of These 4 Approaches

ApproachWhere It’s Useful
Top 3 (Exactly 3, No Extra Ties)Competitions, business reports, funding allocation.
Top 3 + All Duplicates of NthLeaderboards, performance reviews, sales rankings.
Top 3 (Distinct Values Only)Pricing strategies, salary bands, data summaries.
Top 3 (Distinct Values + All Occurrences)HR & rewards, market research, visualizing tied results.

Conclusion

The traditional LARGE and RANK methods have limitations, especially when handling ties. With these four improved formulas, you can highlight the largest 3 values in each row in Google Sheets while controlling tie behavior according to your needs.

By selecting the right formula, you ensure that your data visualization is both accurate and meaningful.

Resources

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...

4 COMMENTS

    • Hi, Chris,

      The same formula will work in a vertical range.

      For example, for the range C2:C15, you can use the following highlight rule.

      =and(len($C$2:$C$15),C2>=large(arrayformula(n($C$2:$C$15)),3))

  1. Hello,

    Is there a way to do this but not highlight a duplicate lower value? For instance, if my values are 50, 49, 48, 48, 40, and 30, I would only want 50, 49, and the first 48 highlighted, not both 48s.

    Thank you.

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.