Going Stellar

Home/Google Sheets reference

Google Sheets function · Array

MAP in Google Sheets: syntax and examples

MAP applies a LAMBDA to each value of an array, or to matching values of several arrays, and returns the results as an array. Use it when a custom calculation per row is too complex for a plain ARRAYFORMULA.

Syntax

MAP(array1, [array2, ...], LAMBDA)

Arguments

ArgumentTypeRequiredWhat it does
array1arrayyesThe first array or range. LAMBDA runs once per value.
array2, ...arraynoMore arrays of the same size, one LAMBDA argument for each.
lambdalambdayesA LAMBDA that takes one name per array and returns one value.

Examples

The examples use this table, starting in A1:

AB
110
220
330
440
=MAP(A2:A5, LAMBDA(x, x*x))

Result:

1
4
9
16

Square every value in the range. The result spills down.

Run in a Google Sheet (English US locale) on .

=MAP(A2:A5, B2:B5, LAMBDA(a, b, a+b))

Result:

11
22
33
44

Two ranges: LAMBDA gets one value from each, row by row.

Run in a Google Sheet (English US locale) on .

=MAP(A2:A5, LAMBDA(x, IF(x>2, "big", "small")))

Result:

small
small
big
big

Return text based on a condition for every value.

Run in a Google Sheet (English US locale) on .

=SUM(MAP(A2:A5, LAMBDA(x, x*x)))

Result: 30

MAP returns an array, so another function can consume it.

Run in a Google Sheet (English US locale) on .

=MAP({"a b"; "c d"}, LAMBDA(t, UPPER(t)))

Result:

A B
C D

Works on a typed array as well.

Run in a Google Sheet (English US locale) on .

Common errors

  • The LAMBDA needs one name per array. MAP(A2:A5, LAMBDA(x, y, x)) has one array and two names, and returns #N/A.
  • All arrays must have the same size. A four-row range with a three-row range returns #VALUE!.
  • The last argument must be a LAMBDA. A plain number such as MAP(A2:A5, 5) returns #N/A. A LAMBDA that returns a row such as {x, x} makes MAP spill into two columns.
  • The result spills over neighbouring cells, so keep the cells below and to the right empty.

Compared with Excel

Same syntax in Excel.

Sources

  1. MAP (Docs Editors Help)

Markdown version · All functions