Get Max Date in Each Row Using an Array Formula in Google Sheets

Published on

We can consider using a few functions or combo array/non-array formulas to get the max date in each row in Google Sheets. 

The two main functions for this are Max and Large. But we can also consider using Query and Dmax.

What about combinations? Here are a few of them.

  1. Sortn + Transpose.
  2. Sort + Transpose + Array_Constrain.
  3. Dmax + Transpose.

All the above discussions were about non-array formulas.

What about an array formula to return the max date in each row in Google Sheets?

In that case, we can try the Dmax + Transpose combination formula.

But now, i.e., since the introduction of the new function bundle, we can use the Max function with Byrow Lambda to get the latest dates row-wise.

In this tutorial, you can get the three best formulas to return the recent/latest date in each row in a column.

They are;

  1. Max – Non-Array Formula (we will use this function in a combination formula to remove text strings, blanks, and zero values in the range).
  2. Dmax + Transpose – Array Formula.
  3. Max + Byrow (the array version of option # 1 above) – Recommended!

Sample Data and Non-Array Formula

Assume you have a table that contains a few columns of data.

The first column is for serial numbers, and the second is for employee names.

The first row, after the first two columns, contains activity names. The completion dates by different employees/assignees are below them.

I Want to find the latest completion date of the activities by assignees in every row.

In such a case, we can use a MAX-based combination formula to find the max date in each row as below.

Note:- The formula is for cell I2. We must copy-paste it to the range I3:I10.

Formula # 1:

=iferror(MAX(filter(C2:G2,datevalue(C2:G2))))
Max Date in Each Row in Google Sheets

Out of five activities of “Ryan” (please see the range B2:G2), his latest completion date is 10-Sept-21.

He has completed the other three activities before that.

Why have I used a combination formula above instead of the Max alone?

The above data is not suitable enough to use Max or Large alone because the date range contains blanks, texts, and zeros.

When we use the functions such as Max or Large in such data types, we may encounter two types of errors – #NUM! and an invalid date, i.e., 30-Dec-99.

To avoid them, I have used FILTER and DATEVALUE functions to filter out those unwanted values before max evaluation.

If you want to find the second or nth latest date, replace Max with LARGE.

Formula # 1.1:

=iferror(LARGE(filter(C2:G2,datevalue(C2:G2)),n))

Replace n with 1, 2, or 3.

Get Max Date in Each Row Using DMAX Array Formula in Google Sheets

As you may already know, DMAX is a database function. Its role is to return max from columns, not from rows.

But we can use TRANSPOSE to change the data orientation from rows to columns and use Damx in such data.

I have already explained such usage here – Return the First and Second Highest Values in Each Row in Google Sheets.

We will adopt the same approach here.

Formula # 2 (I2:I10 must be blank beforehand):

=ArrayFormula(
     TO_DATE(
        DMAX(
           transpose({C1:C10,C1:G10}),
           sequence(rows(C2:C10),1,2),
           {"Date 1";if(,,)}
        )
     )
)

It will return the max date in each row but with some invalid dates.

Please see the cells I5, I6, I8, I9, and I10 for the date 30/12/1899.

It’s because the assignees have no submitted dates below their activities.

We want the formula to return blank in those rows.

How?

Let’s call the above formula base_dmax.

We can follow an IF logical test to sort out our issue.

IF(base_dmax >0, base_dmax,)

Let’s code a new formula based on it.

=ArrayFormula(
     TO_DATE(
        if(
           DMAX(
              transpose({C1:C,C1:G}),
              sequence(rows(C2:C),1,2),
             {"Date 1";if(,,)}
           )>0,
           DMAX(
              transpose({C1:C,C1:G}),
              sequence(rows(C2:C),1,2),
              {"Date 1";if(,,)}
           ),
        )
     )
)

Replace the I2 array formula with the above one.

Get Max Date in Each Row Using MAX Lambda Array Formula – New!

Please scroll up and see the first formula under the subtitle “Sample Data and Non-Array Formula.”

We can use the BYROW Lambda Helper function to expand that Max formula result.

So, to get the max activity date in each row, we can use the following array formula.

Formula # 3 (I2:I10 must be blank beforehand):

=byrow(C2:G10,lambda(r, iferror(MAX(filter(r,datevalue(r))))))

How to get the second or nth latest date in each row in Google Sheets?

Then use Byrow with Formula # 1.1 as below.

=byrow(C2:G10,lambda(r, iferror(LARGE(filter(r,datevalue(r)),2))))

That’s all. Thanks for the stay. Enjoy!

Example Sheet 221122

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

4 COMMENTS

  1. Hi Mr. Prashanth,

    It works great! Thank you very much. Would you be able to write an explanation about this? Thank you again.

  2. Hi Mr. Prashanth,

    What if I want to mark the maximum date for a certain person? The mark should be applied only to the person with the maximum date, and it should update daily based on the new data added. Thank you.

    Name | Date | Mark
    A | 10 June 2024 |
    B | 11 June 2024 |
    C | 10 June 2024 | x
    A | 12 June 2024 | x
    C | 9 June 2024 |
    B | 13 June 2024 | x
    A | 11 June 2024 |

    • Hi Ramzi,

      You can try this formula in C2:

      =ArrayFormula(LET(name, A2:A, dt, B2:B, uniq, SORTN(SORT(HSTACK(name, dt), 1, 1, 2, 0), 9^9, 2, 1, 1), tbl, IFNA(HSTACK(CHOOSECOLS(uniq, 1)&CHOOSECOLS(uniq, 2), "x"), "x" ), IF(name="", ,IFNA(VLOOKUP(name&dt, tbl, 2, 0)))))

      Replace A2:A and B2:B with the respective name and date column ranges.

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.