FormulaCraft

How to use LAMBDA with SCAN for a running balance in Excel and Google Sheets

Topic:LAMBDA (reusable formulas)
Excel & Google Sheets
=SCAN(0, B2:B7, LAMBDA(acc, x, acc + x))

Try it with your data

Edit the grid or formula, then run it through a real spreadsheet engine — no signup.

Sample data — click any cell to edit

Runs server-side · free · no signup

Step by step

  1. 1Set up a two-column table: dates or labels in A2:A7 and transaction amounts (positive for credits, negative for debits) in B2:B7.
  2. 2In C2, enter =SCAN(0, B2:B7, LAMBDA(acc, x, acc + x)). The formula spills a running balance into C2:C7.
  3. 3The first argument (0) is the opening balance. Change it to your actual opening balance, e.g. 500.
  4. 4SCAN calls the LAMBDA for each element of B2:B7; acc holds the previous row's total, x holds the current transaction amount.
  5. 5The body acc + x accumulates. Replace this with any custom logic — for a running maximum use MAX(acc, x).

Tips

Need it for your exact data?

Describe your columns in plain English and get the precise formula for your sheet, with the right Excel or Sheets syntax.

Frequently asked

Can SCAN handle debits and credits that are in separate columns?

Combine them first with a helper array or MAP: =SCAN(0, MAP(B2:B7, C2:C7, LAMBDA(cr, db, cr - db)), LAMBDA(acc, x, acc + x)).

What happens if a cell in the range is blank?

Blank cells are treated as 0 in numeric SCAN formulas, which is usually correct for a running balance. Add an ISNUMBER check inside the LAMBDA if blanks should be handled differently.

Is SCAN available in all Excel versions?

No. SCAN requires Microsoft 365 or Excel 2024+. It is not available in Excel 2019 or earlier. Google Sheets supports it fully.

More on LAMBDA (reusable formulas)

See all →

Formulas used

Written and reviewed by FormulaCraft Team. Each formula on this page is run through our verification engine before publishing.

Last reviewed: