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.

Lookup Values Under Categories in Excel and Google Sheets

We can use a combination of XLOOKUP and VLOOKUP in both Excel and Google...

Extract Items Under a Category from the Same Column in Excel

In Excel, you can use a combination of the XLOOKUP and DROP functions to...

How to Create a Searchable Table in Excel Using the FILTER Function

Finding specific records, or rows containing the required information, is straightforward in Excel using...

Time Sequences in Excel by Minute, Hour, or Second Increments

Creating time sequences, whether by hour, minute, or second increments in Excel, can be...

More like this

XMATCH Row by Row: Finding Values Across a Range in Google Sheets

Using the BYROW function with XMATCH in Google Sheets allows us to match values...

Limit Formula Expansion to a Specific Row in Google Sheets

In this tutorial, I’ll explain how to limit the expansion of an array formula...

3-D Referencing Structured Data Tables in Google Sheets

When you have several tables within a single sheet—not across multiple sheets in a...

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.