First and Second Highest Values in Each Row in Google Sheets

Published on

With the help of the BYROW and LARGE functions, you can easily find the first, second, or nth highest value in each row in Google Sheets.

Sample Data

Assume you have item descriptions in one column and sales from different regions in the adjacent columns. You can then find each item’s first, second, and third highest sales across these regions. Below is an example of how your data might look:

ItemDelhiMumbaiBangaloreKochin
Item A500350620410
Item B450570320700
Item C610390550640
Item D520460490380

The above data is in the range A1:E5. Let’s find the first, second, and third highest values in each row and display them in F2:F5, G2:G5, and H2:H5, respectively.

First, second, and third highest values in each row of a Google Sheets table

Regular Non-Array Solutions

Finding the First Highest Value:

To find the first highest value for each row, enter the following LARGE formula in cell F2 and drag the fill handle down:

=LARGE(B2:E2, 1)

Finding the Second Highest Value:

To get the second highest value, replace 1 with 2 in the formula, and then drag it down:

=LARGE(B2:E2, 2)

Finding the Third Highest Value:

For the third highest value, replace 1 with 3 in the formula and drag it down:

=LARGE(B2:E2, 3)

Array Formula to Find the First, Second, and Third Highest Values in Each Row

When you want to consider a row, rather than a single cell, as a single entity and apply a LAMBDA function to each row, you can use the BYROW function.

The syntax is:

BYROW(array_or_range, lambda)

In this case, the array or range is B2:E5. Let’s write the LAMBDA function to apply to each row.

Finding the First Largest Value

We will start by coding the formula to find the first largest value in each row. For this, we will use the following LARGE formula, which we used earlier in cell F2:

=LARGE(B2:E2, 1)

We can convert this to a LAMBDA function, which follows the syntax:

LAMBDA([name, …], formula_expression)

In the LARGE formula, replace B2:E2 with a meaningful name, such as row, and define that in LAMBDA as follows:

LAMBDA(row, LARGE(row, 1))

The LAMBDA function to find the first largest value in each row is now ready. Simply use this within the BYROW function as follows:

=BYROW(B2:E5, LAMBDA(row, LARGE(row, 1)))

Clear any values in F2:F5 and enter this formula in F2 to get the first largest value in each row.

Finding the Second and Third Largest Values

To get the second, third, or nth largest value in each row, replace 1 with n, such as 2, 3, etc. For example:

  1. For the second largest value:
    =BYROW(B2:E5, LAMBDA(row, LARGE(row, 2)))
  2. For the third largest value:
    =BYROW(B2:E5, LAMBDA(row, LARGE(row, 3)))

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.

Highlight Upcoming Birthdays in Google Sheets

When highlighting upcoming birthdays in Google Sheets, one important aspect is ignoring the year...

Compare Two Tables for Differences in Excel

To compare two tables with similar data for differences, you can use the XLOOKUP...

Calculate Weighted Average in Pivot Table in Google Sheets

You can calculate a weighted average in a Pivot Table using a custom formula...

Summarize Data and Keep the Last Record in Google Sheets

In Google Sheets, we can summarize data (like sum, average, min, max, count) using...

More like this

Highlight Upcoming Birthdays in Google Sheets

When highlighting upcoming birthdays in Google Sheets, one important aspect is ignoring the year...

Calculate Weighted Average in Pivot Table in Google Sheets

You can calculate a weighted average in a Pivot Table using a custom formula...

Summarize Data and Keep the Last Record in Google Sheets

In Google Sheets, we can summarize data (like sum, average, min, max, count) using...

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.