Highlight Max Value Leaving Duplicates in Row-Wise in Google Sheets

To highlight the max value while leaving duplicates row-wise in Google Sheets, you can use a combination of the AND, RANK, UNIQUE, and COUNTIF functions.

You can use the MAX function to extract the max value in a row. When you want to find it in each row, you can use the BYROW lambda with MAX. However, instead of extracting the value, you might want to quickly visualize the max value in each row. This is where conditional formatting becomes useful.

Real-Life Example: Employee Sales Performance

Consider a scenario where each row represents sales figures for different employees. Their sales amounts are spread across columns, where each column represents a different month.

You can apply a highlight rule to emphasize the max sale of each employee in their records. If an employee has the same max sale in multiple months, you may want to highlight only one occurrence to avoid clutter.

If that is the case, use the following formula to highlight the max value while leaving duplicates row-wise in Google Sheets:

=AND(RANK(A1, UNIQUE($A1:$Z1, TRUE))=1, COUNTIF($A1:A1, A1)<2)

Replace A1 with the first cell in the row, $A1:$Z1 with the reference to the entire row, and $A1:A1 with the first cell reference as a range.

You can replace RANK with MAX, but using RANK makes the formula more flexible. You can use it to highlight the first, second, and third largest unique values with different colors, which we will discuss later.

Highlighting Max Value While Leaving Duplicates in Row-Wise – Example

Sample Sales Data

Sample Data

Steps to Highlight the Max Value While Leaving Duplicates in Each Row

  1. Select the range to highlight (e.g., B2:F5).
  2. Click Format > Conditional Formatting.
  3. Under Format rules, select Custom Formula Is.
  4. Enter the following formula:=AND(RANK(B2, UNIQUE($B2:$F2, TRUE))=1, COUNTIF($B2:B2, B2)<2)
  5. Choose a fill color (e.g., Blue).
  6. Click Done.

This will highlight the max value while leaving duplicates unhighlighted in each row.

Conditional Format Panel Settings for Highlighting Max Value While Leaving Duplicates in Row-Wise

Formula Explanation

The formula used is:

=AND(RANK(B2, UNIQUE($B2:$F2, TRUE))=1, COUNTIF($B2:B2, B2)<2)
  • RANK(B2, UNIQUE($B2:$F2, TRUE))=1 – Returns TRUE if the rank of B2 in the unique row range is equal to 1.
  • COUNTIF($B2:B2, B2)<2 – Ensures that the value in B2 appears only once up to that point in the row, avoiding duplicate highlights.
  • The AND function ensures that both conditions are met before highlighting the cell.

The RANK test applies to each value in the row with the row range, and the COUNTIF test applies to each value dynamically as it progresses through the row.

Proper use of relative and absolute cell references is crucial for correctly highlighting the max value while leaving duplicates row-wise in Google Sheets.

Highlight the Second and Third Largest Values While Leaving Duplicates in Each Row

To highlight the second largest value while leaving duplicates, modify the formula by replacing =1 with =2:

=AND(RANK(B2, UNIQUE($B2:$F2, TRUE))=2, COUNTIF($B2:B2, B2)<2)

For the third largest value, replace =1 with =3:

=AND(RANK(B2, UNIQUE($B2:$F2, TRUE))=3, COUNTIF($B2:B2, B2)<2)

Apply each rule separately, using different fill colors (e.g., Blue, Light Blue, and Grey) to make them stand out.

Highlight Second and Third Largest Values While Leaving Duplicates Individually

By following these steps, you can effectively highlight the max value while leaving duplicates row-wise in Google Sheets, ensuring a clear and clutter-free visual representation of important 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...

3 COMMENTS

  1. Hello,

    Sorry for this off-topic here, but really curious if it would be possible to do something like this in Google Sheets (pls see YouTube video).

    — link removed by admin —

    Kind regards.

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.