Looping With MAP and REDUCE
Apply a LAMBDA across an array to transform or accumulate values.
Looping With MAP and REDUCE is a free Excel Formulas Academy lesson on CoddyKit — lesson 3 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Excel Formulas Academy learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.
Looping Without Code
Sometimes you want to apply the same calculation to every value in a range, or boil a whole range down to a single number. In programming this is a loop. In modern spreadsheets, MAP and REDUCE do this for you using LAMBDA.
- MAP transforms each element of an array into a new element
- REDUCE combines all elements into one accumulated result
Both take a LAMBDA that describes what to do with each value. They are available in Microsoft 365 and Google Sheets.
How MAP Works
MAP walks through an array and applies a LAMBDA to each item, producing a new array of the same size. The LAMBDA's parameter receives one element at a time.
The pattern is: give MAP the array, then a LAMBDA whose parameter stands for each value. MAP spills the transformed results across cells automatically.
=MAP(array, LAMBDA(value, calculation))A First MAP Example
Suppose A2:A6 holds five prices and you want each one increased by 10 percent. MAP applies the markup to every value at once.
The LAMBDA parameter p represents each price in turn. MAP returns five results, one per input cell, spilling down the column.
No dragging the fill handle, no copying. One formula handles the whole range.
=MAP(A2:A6, LAMBDA(p, p*1.1))MAP With Two Arrays
MAP can walk through two arrays in parallel. The LAMBDA then takes two parameters, one from each array, matched position by position.
Here we multiply quantities in A2:A6 by prices in B2:B6 to get line totals. The parameter q pairs with each quantity and pr with each price.
Both arrays must be the same size or you will get an error.
=MAP(A2:A6, B2:B6, LAMBDA(q, pr, q*pr))How REDUCE Works
REDUCE collapses an array into a single value. It carries an accumulator that updates with each element.
It takes three things: a starting value for the accumulator, the array, and a LAMBDA with two parameters, acc (the running total) and value (the current element). The LAMBDA returns the new accumulator each step.
=REDUCE(start, array, LAMBDA(acc, value, new_accumulator))A First REDUCE Example
Let's sum a range with REDUCE (yes, SUM does this too, but it shows the mechanics clearly).
We start the accumulator at 0. For each value in A2:A6, the LAMBDA adds it to acc. After the last element, acc holds the total.
If the values were 10, 20, 30, the accumulator would step 0, 10, 30, 60, ending at 60.
=REDUCE(0, A2:A6, LAMBDA(acc, v, acc + v))REDUCE for a Running Product
Change the operation and REDUCE does something new. To multiply all values together, start the accumulator at 1 and multiply each step.
This computes a product, useful for things like compound growth factors. The starting value matters: use 0 for sums and 1 for products, since those are the neutral starting points.
=REDUCE(1, A2:A6, LAMBDA(acc, v, acc * v))Combining MAP and REDUCE
You can transform with MAP and summarize with REDUCE in one formula. A common task is summing the squares of a range.
Here MAP squares each value, then REDUCE adds them up starting from 0. The MAP result becomes the array that REDUCE consumes.
=REDUCE(0, MAP(A2:A6, LAMBDA(x, x^2)), LAMBDA(acc, v, acc + v))MAP and REDUCE in Google Sheets
Both functions exist in Google Sheets with identical syntax. MAP applies a LAMBDA to each element; REDUCE accumulates with a starting value, an array, and a two-parameter LAMBDA.
Sheets also offers related helpers like SCAN, which is like REDUCE but returns every intermediate accumulator instead of just the final one. Excel has SCAN too.
=SCAN(0, A2:A6, LAMBDA(acc, v, acc + v))Tips and Gotchas
A few things to remember:
- In MAP, the LAMBDA must return one value per element
- In REDUCE, the LAMBDA must always return the new accumulator, never forget it
- Pick the right start value: 0 for sums, 1 for products, an empty string for text joins
- Arrays passed together must share the same dimensions
When in doubt, test your LAMBDA inline on a single value first.
When to Use Each
Reach for MAP when you want a result for each input, like applying a markup or formatting every value.
Reach for REDUCE when you want to fold many values into one, like a custom total, a concatenation, or a maximum found through your own logic.
Together they let you express loops that older spreadsheets simply could not do in a single formula.
Quick Check
Test your understanding of REDUCE.
Recap: Looping With MAP and REDUCE
You learned to loop over arrays with LAMBDA-powered functions.
- MAP transforms each element into a new element, returning an array
- REDUCE folds an array into one value using an accumulator
- Choose a sensible start value: 0 for sums, 1 for products
- MAP can pair multiple arrays; combine MAP and REDUCE for powerful one-line summaries
- SCAN shows every intermediate step
Next you will save your LAMBDAs as named functions for clean, reusable formulas across the workbook.
=REDUCE(0, MAP(A2:A6, LAMBDA(x, x^2)), LAMBDA(acc, v, acc + v))Frequently asked questions
Is the “Looping With MAP and REDUCE” lesson free?
Yes — the full text of “Looping With MAP and REDUCE” is free to read here on the web, and the Excel Formulas Academy course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Excel Formulas Academy course, upgrade to CoddyKit PRO.
What will I learn in “Looping With MAP and REDUCE”?
Apply a LAMBDA across an array to transform or accumulate values. You practise Excel Formulas Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.
Do I need any experience to start Excel Formulas Academy?
No prior experience is required. Excel Formulas Academy on CoddyKit is structured for beginners through advanced learners; this is — lesson 3 of 4, so you can start here or from the beginning and move at your own pace.
How long does the “Looping With MAP and REDUCE” lesson take?
Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.
Can I write and run code in this Excel Formulas Academy lesson?
Yes. Every Excel Formulas Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.
All lessons in this course
- Naming Steps With LET
- Defining Custom Functions With LAMBDA
- Looping With MAP and REDUCE
- Cleaner Formulas With Named LAMBDAs