Excel LAMBDA Lesson 5: REDUCE and SCAN (Running Balances, Multi-Replace)

Excel LAMBDA Lesson 5: REDUCE and SCAN (Running Balances, Multi-Replace) 1

πŸ“Ž This article includes 1 downloadable practice file ↓

⏱ 2 min read

πŸ“˜ Excel LAMBDA Library Course Β· Lesson 5 of 8

Advertisement
In this article
  1. Running bank balance
  2. MULTIREPLACE: many SUBSTITUTEs in one
  3. Common mistakes
  4. Practice

REDUCE and SCAN walk through a list one item at a time, carrying a running value (the accumulator).

=REDUCE(start, list, LAMBDA(acc, item, new_acc))   β†’ only the final value
=SCAN(start, list, LAMBDA(acc, item, new_acc))     β†’ every step

Running bank balance

=SCAN(1000, {-200, 500, -300}, LAMBDA(bal, txn, bal + txn))   β†’ 800, 1300, 1000
=MIN(SCAN(...))                                                β†’ 800, the lowest point

That lowest point is what a bank looks at for minimum-balance charges, and it’s one formula.

MULTIREPLACE: many SUBSTITUTEs in one

MULTIREPLACE =LAMBDA(t, old, new,
   REDUCE(t, SEQUENCE(COLUMNS(old)),
     LAMBDA(a, i, SUBSTITUTE(a, INDEX(old, i), INDEX(new, i)))))

=MULTIREPLACE("ABC Pvt Ltd", {"Pvt","Ltd"}, {"Private","Limited"})   β†’ ABC Private Limited

Point old and new at two columns of a table and your replacement list becomes editable without touching the formula. Turn the columns into rows with TRANSPOSE, or use ROWS instead of COLUMNS.

πŸ’‘ REDUCE can count too: =REDUCE(0,B2:B6,LAMBDA(a,v,a+(v>100))). For simple counts COUNTIF is faster, but the pattern works for rules COUNTIF can’t express.

Common mistakes

  • Argument order inside the LAMBDA: always (accumulator, item).
  • Returning an array from REDUCE needs care; for lists of results use SCAN or MAP.

Practice

Download the workbook below. The tasks call each function inline, like =LAMBDA(x,x*2)(A2), so the file works on any Microsoft 365 PC; in your own files, save them by name in Name Manager. The Check column turns green when you’re right.

πŸ“Ž Practice files for this article

Free to use for learning. Files with macros (.bas) are plain text β€” import them with Alt+F11 β†’ File β†’ Import File, and always test on a copy.

Advertisement
✨ Ask AI about this article

Stuck on a step? Ask a question and the AI answers using this article.

Free Β· AI can be wrong

Leave a Reply

Your email address will not be published. Required fields are marked *