formulastreak

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

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.

Saturday bakery stall · edit D2 and watch it recalculate
Click a cell (or use the arrow keys) to insert its address · Enter shows the resultD2 = $91.00
ABCD
1ItemSoldPriceTotal
2Sourdough loaf14$6.50$91.00
3Croissant32$2.80$89.60
4Cinnamon bun21$3.20$67.20
5Baguette18$3.00$54.00
6Rye loaf9$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. 1. LAMBDA: Describes your own function: given Q and P, it works out Q times P.
    • parameter = `Q`: a name for each input and `p`
    • calculation = `P`: what to work out with them
    • calculation = `Q*P`: what to work out with them
  2. 2. MAP: Runs the result of step 1 on each value of B2:B6, C2:C6 and spills one result per value.
    • range1 = `B2:B6`: the first range
    • range2 = `C2:C6`: optional
    • LAMBDA(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

ArgumentRequiredWhat it is
array1YesThe first range or array to go through, one value at a time.
array2, …NoMore 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.
lambdaYesAlways 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:C6 gives 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

  • #VALUE!: The LAMBDA has the wrong number of parameters for the arrays given, or the arrays differ in size.
  • #SPILL!: Cells in the way of the result aren't empty.
  • #NAME?: The file is open in Excel 2021 or older, which don't have MAP or LAMBDA.

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.

Practise MAP on a live sheet

Lesson 42, LAMBDA (Unit 12, LET and LAMBDA), has 7 graded exercises, checked instantly, with steps and hints when you're stuck. Pro