How to Calculate Days Since Last Payment in Google Sheets (Array Formula)

Published on

Tracking payments in Google Sheets often requires knowing how many days have passed since the last payment. Manually calculating this for each row can be tedious, especially if you’re dealing with months of data. In this guide, I’ll show you how to use an Array Formula in Google Sheets to automatically calculate the days since the previous payment — no dragging formulas down required.

This approach is especially useful for financial trackers, invoices, or subscription records where you need to quickly see gaps between payments.

I’ll cover two approaches:

  • A Lambda formula — simple and straightforward, but it may lag with very large datasets.
  • A classic array formula — slightly more complex but faster and more reliable for bigger sheets.

Don’t worry, I’ll walk you through both along with explanations.

Sample Scenario

Imagine you maintain a payment log with columns for Date, Amount Due, and Amount Paid. You want Google Sheets to automatically calculate the number of days since the last payment whenever a new entry appears.

Here’s an example table:

Google Sheets table showing days since last payment auto-calculated

With the right Array Formula, the “Days Since Last Payment” column is filled automatically without any manual work.

Calculate Days Since Last Payment Using MAP + LAMBDA

If your data is in range A1:C, enter this formula in cell D2:

=MAP(
  SEQUENCE(ROWS(A2:A)), A2:A, C2:C,
  LAMBDA(seq, dt, pmt,
    IF(pmt="","",
      IFERROR(
        dt - MAX(FILTER(A2:A, (ROW(A2:A) < seq + ROW(A2)-1) * (C2:C <> ""))),
        ""
      )
    )
  )
)

This formula skips the first payment date. From the second payment onward, it fetches the immediately earlier payment date and subtracts it from the current one. That’s how it calculates the days since the last payment in Google Sheets.

Formula Breakdown

We pass three arrays into MAP:

  • SEQUENCE(ROWS(A2:A)) → generates sequence numbers from 1 up to the number of rows in the range A2:A.
  • A2:A → the date range.
  • C2:C → the payment range.

The LAMBDA assigns these names: seq (sequence number), dt (date), and pmt (payment).

  • IF(pmt="", "", … ) → skips empty payment rows.
  • MAX(FILTER(A2:A, (ROW(A2:A) < seq + ROW(A2)-1) * (C2:C <> ""))) → finds the most recent payment date before the current row.
  • Subtracting this from dt gives the days since the last payment.

Calculate Days Since Last Payment Using a Classic Array Formula

For large datasets, this formula is more efficient. Place it in D2:

=ArrayFormula(let(
   pRows, query(filter(row(A2:A), C2:C>0), "Select * offset 1", 0), 
   dt, FILTER(A2:A, C2:C>0), 
   array_1, VSTACK(dt, NA()), 
   array_2, VSTACK(NA(), dt), 
   nd, TOCOL(array_1-array_2, 3), 
   IFNA(VLOOKUP(ROW(A2:A), hstack(pRows, nd), 2, 0))
))

This approach calculates all differences at once and then maps them back to the correct rows. It’s slightly harder to read, but it’s faster for long sheets.

Formula Breakdown

  • pRows → returns row numbers of payment entries, skipping the first.
  • dt → filters payment dates.
  • array_1 and array_2 → align shifted payment dates using VSTACK.
    Shifted payment dates aligned side by side in Google Sheets to calculate days since last payment
  • nd → calculates the differences between consecutive payment dates.
  • VLOOKUP → assigns those differences back to the correct rows.

Resources

Prashanth KV
Prashanth KV
Your Trusted Google Sheets and Excel Expert Prashanth KV is a Diamond Product Expert in Google Sheets, officially recognized by Google for his contributions to the Docs Editors Help Community and featured in the Google Product Experts Directory. Explore his blog to learn advanced formulas, automation tips, and problem-solving techniques to elevate your spreadsheet skills.

Top Discussions

More like this

Pivot Table Formatting, Output & Special Behavior in Google Sheets

Pivot Tables in Google Sheets are powerful—but they can get tricky once you move...

Pivot Table Calculations & Advanced Metrics in Google Sheets

When it comes to built-in tools for data analysis and visualization in Google Sheets,...

Google Sheets Pivot Table Tutorial: Basics, Setup, and Date Grouping

The easiest way to summarize, analyze, and report data in Google Sheets is by...

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.