How to Find Max Value in Each Row in Google Sheets

To find the maximum value in each row in Google Sheets, you can use three main formula options: the MAX function with BYROW, a DMAX-based formula, and a QUERY-based formula.

Before the introduction of the BYROW function (a Lambda helper function), the QUERY and DMAX methods were the primary options. I’ll share all three options with you, but the MAX and BYROW combination is the simplest and most efficient. So, let’s start with that.

For this example, we’ll use the sample data in A1:F10, and the range we want to evaluate for maximum values is B2:F10.

Sample data for finding the maximum value in each row

MAX and BYROW Combo for Getting Max Value in Each Row

To get the maximum value in each row, you can use the following simple, non-array formula in cell G2 and drag it down to G10:

=MAX(B2:F2)

However, we can convert this into an array formula to avoid dragging the formula manually.

Steps to Convert It Into an Array Formula:

  1. First, create a custom LAMBDA function:
    LAMBDA(row, MAX(row))
  2. Next, apply this LAMBDA function to each row using the BYROW function:
    =BYROW(B2:F10, LAMBDA(row, MAX(row)))

This formula in cell G2 will return the row-wise maximum value for each row in the specified range. This method is the simplest and most efficient way to find the max value in each row in Google Sheets.

QUERY-Based Formula for Getting Max Value in Each Row

Another option is to use the QUERY function. However, by default, QUERY returns the maximum values for each column, not each row. To get the max values for rows, we need to transpose the data.

Here’s the formula to get the max values for each row:

  1. Transpose the data and apply QUERY:
    =INDEX(TRANSPOSE(QUERY(TRANSPOSE(B2:F10), "SELECT MAX(Col1), MAX(Col2), MAX(Col3), MAX(Col4), MAX(Col5), MAX(Col6), MAX(Col7), MAX(Col8), MAX(Col9)", 0)), 0, 2)
    The INDEX function is used here to remove the label column returned by the QUERY.
    Find the maximum value in each row using the QUERY function in Google Sheets
  2. To avoid hardcoding the column names (MAX(Col1), MAX(Col2)…), we can dynamically generate this part using SEQUENCE, COLUMNS, and TEXTJOIN:
    =ArrayFormula(TEXTJOIN("),", TRUE, "MAX(Col"&SEQUENCE(COLUMNS(TRANSPOSE(B2:F10))))&")")
  3. Final dynamic QUERY formula:
    =INDEX(TRANSPOSE(QUERY(TRANSPOSE(B2:F10), "Select "&TEXTJOIN("),", TRUE, "MAX(Col"&SEQUENCE(COLUMNS(TRANSPOSE(B2:F10))))&")")), 0, 2)

This method is a bit more complex than the BYROW method but works efficiently, especially when using dynamic ranges.

DMAX-Based Formula for Getting Max Value in Each Row

Before the introduction of the BYROW function, another method to find the max value in each row was using the DMAX function. However, like QUERY, DMAX is designed to return the max value from columns rather than rows.

To use DMAX for rows, we need to transpose the data and add a structured header.

Syntax:

DMAX(TRANSPOSE(database), field, criteria)

Steps to Use DMAX for Max Value in Each Row:

  1. Add a header row by stacking row numbers to act as the new “header”:
    =HSTACK(ROW(B2:B10), B2:F10)
  2. Transpose the data to structure it properly for the DMAX function:
    TRANSPOSE(HSTACK(ROW(B2:B10), B2:F10))
    Structured data for the DMAX function
  3. Use this transposed data as the database for the DMAX function. Here is the final formula:
=ArrayFormula(
   DMAX(
      TRANSPOSE(HSTACK(ROW(B2:B10), B2:F10)), 
      SEQUENCE(ROWS(B2:B10)), 
      {IF(,,); IF(,,)}
   )
)

In this formula, SEQUENCE(ROWS(B2:B10)) dynamically returns the column index (field) for the output, and {IF(,,); IF(,,)} serves as an empty criteria range.

This formula will return the maximum values for each row, but it’s more complex and less intuitive compared to the BYROW function.

Conclusion

Of the three methods, which one is best for finding the max value in each row in Google Sheets?

I would recommend the MAX and BYROW combination. It’s straightforward and works efficiently in most cases. However, if you are dealing with very large datasets and the BYROW formula runs into performance issues, you might consider using the DMAX method for better efficiency.

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.

Hierarchical Numbering Sequences in Excel

Creating hierarchical numbering sequences in an Excel spreadsheet can significantly improve the way you...

How to Easily Repeat a Sequence of Numbers in Excel

Excel offers multiple ways to accomplish tasks, and the simplicity of each approach depends...

Create a Sequence of Dates at Every Nth Row in Excel (Dynamic Array)

Would you like to create a sequence of dates in every nth row in...

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

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

24 COMMENTS

  1. Hi Guys,

    I need help…

    I have 5 columns in google sheets – example column 1 – “visual”, column 2 – “auditory”, column 3 – “kinaesthetic”, column 4 – “taste”, column 5 – “smell”.

    I want to add a formula in column 6 to find the highest value in the row for these five columns, but I want it to return the column name.

    Any help, comments, or formulas would be of great help.

    Thanks

  2. Hi, I think I’ve found a better method of doing this.

    Since I wasn’t able to use your method because I had too many rows (exceeding TEXTJOIN length limit), I wrote a function RowWiseMax() in JavaScript and used that. But then I figured out another way to do row-wise max using just the built-in functions, which works with thousands of rows.
    Here it is:
    =ARRAYFORMULA(DMAX(TRANSPOSE(A3:G6), SEQUENCE(ROWS(A3:G6)), {IF(,,);IF(,,)}))

  3. The formulas in the above article are quite brilliant! While I already knew how those individual functions work in GSheets, the clever way shown here of combining them together was eye-opening.
    However, I was stymied by Google’s column limit when I tried to use it on a dataset that was 7000+ rows long.
    A simpler workaround I discovered was as follows (assume in this example that the top row is header):

    =ArrayFormula(if(GTE(A2:A,B2:B),A2:A,B2:B))

    While MAX doesn’t play nice with array formulas, I haven’t had trouble with many of the other comparators, and since the GTE function returns “TRUE” if the first term is >= the second term, a simple “if” statement seems to do the trick. Also, it seems to have the same ability of not requiring a defined “end” to the dataset, and seems to work fine on both short or long spreadsheets without worrying about where the last row is found.

    Please beware that I have not rigorously tested this—I’ve only used it for my specific needs on a spreadsheet for work. Therefore, if someone out there sees a flaw with this, please let me know so I can save myself a headache down the road! 🙂

    • Hi, E Kain,

      Today I got time and checked your formula. Of course, it works! But assume you have 20 columns. Then the formula would be very complex and difficult code without error.

      My formula works well! But when there are a large number of rows, it fails miserably due to the limitation of Join/Textjoin functions.

      Thanks.

    • I know this is an old thread, but just for others to understand the complexity expansion of E Kain’s proposal, I wanted to show this example:

      With two columns (as suggested), the formula is seemingly simple:

      =ArrayFormula(if(GTE(D97:D99,E97:E99),D97:D99,E97:E99))

      But already at three columns, the formula becomes hard to read (and especially maintain):
      =ArrayFormula(if(GTE(if(GTE(D93:D95,E93:E95),D93:D95,E93:E95),
      if(GTE(E93:E95,F93:F95),E93:E95,F93:F95)),if(GTE(D93:D95,E93:E95),D93:D95,E93:E95),
      if(GTE(E93:E95,F93:F95),E93:E95,F93:F95)))

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.