Dynamic arrays function
MAP function in Google Sheets and Excel
MAP runs a LAMBDA on every value of one or more ranges and spills one result per value, in the same shape.
Checked against Microsoft's and Google's documentation on · Example calculated on a live sheet
- Excel 2016
- Excel 2019
- Excel 2021
- Excel 2024
- Microsoft 365
- Google Sheets
Syntax
MAP(array1, lambda_or_array<#>)Arguments in [brackets] are optional. Google Sheets writes it MAP(array1, [array2, ...], LAMBDA).
Example
=MAP(B2:B6,C2:C6,LAMBDA(q,p,q*p)) reads: For each row of the stall, hand the number sold (B2:B6, called q) and the price (C2:C6, called p) to a LAMBDA that multiplies them, and spill the five line totals.
| A | B | C | D | |
|---|---|---|---|---|
| 1 | Item | Sold | Price | Total |
| 2 | Sourdough loaf | 14 | $6.50 | $91.00 |
| 3 | Croissant | 32 | $2.80 | $89.60 |
| 4 | Cinnamon bun | 21 | $3.20 | $67.20 |
| 5 | Baguette | 18 | $3.00 | $54.00 |
| 6 | Rye loaf | 9 | $7.00 | $63.00 |
D2 to D6 show every line total: $91.00 for the sourdough down to $63.00 for the rye.
How the spreadsheet calculates it
Runs the result of LAMBDA (step 1) on each value of B2:B6, C2:C6 and spills one result per value.
- 1. LAMBDA: Describes your own function: given
QandP, it works outQtimesP.parameter=`Q`: a name for each input and `p`calculation=`P`: what to work out with themcalculation=`Q*P`: what to work out with them
- 2. MAP: Runs the result of step 1 on each value of
B2:B6,C2:C6and spills one result per value.range1=`B2:B6`: the first rangerange2=`C2:C6`: optionalLAMBDA(a, b, calculation)=the result of step 1: what to do with each pair
More MAP examples
=MAP(B2:B6,LAMBDA(q,IF(q>=20,"Busy","Quiet")))A label for every row: Busy for 20 or more sold.=SUM(MAP(B2:B6,C2:C6,LAMBDA(q,p,q*p)))The stall's takings in one cell: the line totals added up.=MAP(A2:A6,LAMBDA(t,UPPER(TRIM(t))))Every item name trimmed and in capitals.=MAP(B2:B6,C2:C6,LAMBDA(q,p,ROUND(q*p*1.08,2)))Each line total with 8% added, rounded to cents.
Paste any of these into the formula explainer to see it step by step.
Tips
- Give the LAMBDA's parameters short, meaningful names (q and p for quantity and price) so the formula reads like a sentence.
- Check whether simple array maths does the job first; use MAP when the calculation needs IF, a lookup or LET.
- Leave empty cells below the formula for the whole result to spill into.
- Wrap MAP in SUM to total its results without showing them:
SUM(MAP(…)).
What MAP is used for
Labelling or scoring every row with a calculation too complex for plain array maths, cleaning a column of values in one spilled formula, and combining two columns pair by pair, such as quantity and price, without a helper column.
Arguments
| Argument | Required | What it is |
|---|---|---|
| array1 | Yes | The first range or array to go through, one value at a time. |
| array2, … | No | More ranges of the same size; the LAMBDA then gets one value from each, from the same position.Watch out: A range of a different size breaks the pairing. |
| lambda | Yes | Always the last argument: a LAMBDA with one parameter per array, such as LAMBDA(q, p, q*p) for two arrays.Watch out: A LAMBDA with the wrong number of parameters gives #VALUE!. |
Common mistakes
Ranges of different sizes: #VALUE!.
Writing a LAMBDA with one parameter while passing two ranges: Microsoft's page says the LAMBDA needs a parameter for each array, otherwise you get #VALUE!.
Reaching for MAP when plain array maths would do:
=B2:B6*C2:C6gives the same five totals. MAP earns its place when each value needs an IF, a lookup or several steps.Typing in the cells below the formula, which blocks the spill (#SPILL!).
In Google Sheets
Google Sheets has MAP. Google writes it MAP(array1, [array2, ...], LAMBDA): the same order, with the LAMBDA last and one parameter per array, so a formula like the example works in both apps.
Errors you may see with MAP
Questions
What's the difference between MAP and BYROW?
MAP hands the LAMBDA one cell at a time (or one cell from each range), so it returns one result per cell. BYROW hands it a whole row, so you can SUM or MAX across the row and get one result per row.
Can MAP use an IF inside?
Yes, and that's its best use: MAP(B2:B6, LAMBDA(q, IF(q>20, "Busy", "Quiet"))) labels every row with one formula. Any calculation that works on a single value works inside the LAMBDA.
Why not just fill a formula down?
You can. MAP gives one formula that spills, so there's nothing to copy, and the result grows if you point it at a bigger range. In a shared file, a filled-down column is easier for colleagues on older versions to read.
Does MAP need LAMBDA to be learned first?
Yes: the last argument is a LAMBDA. The LAMBDA guide shows how parameters and the calculation fit together.
Sources
Official documentation the facts on this page were checked against.