Logical functions

MAP

Matches all 35 recorded answers

Recorded: 35 workbook cells. How we measure this · See the Rust code

Local names in 40 languages
LanguageName in Excel
ArabicMAP
BulgarianMAP
CzechMAPA
DanishTILKNYT
GermanMAP
GreekMAP
English (Australia)MAP
English (United Kingdom)MAP
English (United States)MAP
SpanishMAPEAR
EstonianMAP
FinnishMAP
FrenchMAP
HebrewMAP
CroatianMAP
HungarianMAP
IndonesianMAP
ItalianMAP
JapaneseMAP
KoreanMAP
LithuanianMAP
LatvianMAP
NorwegianTILORDNE
DutchTOEWIJZING
PolishMAPA
Portuguese (Brazil)MAPA
Portuguese (Portugal)MAPA
RomanianMAP
RussianMAP
SlovakMAP
SlovenianMAP
Serbian (Latin)MAP
SwedishMAP
ThaiMAP
TurkishEŞLE
UkrainianMAP
VietnameseMAP
Chinese (Simplified)MAP
Chinese (Hong Kong)MAP
Chinese (Traditional)MAP

Names from Microsoft's support site.

What it does

MAP(array1, [array2, …], lambda)

MAP(array1, [array2, …], lambda) applies a calculation to corresponding positions of one or more arrays and returns the resulting array. The lambda goes last and takes one parameter per input array.

=MAP({1;2;3},LAMBDA(x,x*x)) returns a column containing 1, 4 and 9. With two equally shaped arrays, =MAP({1;2},{10;20},LAMBDA(x,y,x+y)) returns 11 and 22. Positions are paired; MAP does not form every possible pair of inputs.

Try it

Input cells (optional)

Example: {"B2": 3, "B3": 4}. A1 holds the formula. Other cells need values before a formula can read them.

Enter a formula, then calculate.

Runs locally in your browser with OneCalc. Its answer may differ from Excel. Use English function names and commas between arguments.

Square the example column, then change x*x to IF(x>1,x*x,0). Use arrays with the same shape when adapting the two-input example. Mismatched shapes need their own compatibility checks.

Quirks

Microsoft documents #VALUE! when the final argument is not a valid lambda or its parameter count is wrong. A result must fit one output position; a lambda that returns an array introduces a separate nested-array problem rather than automatically expanding the result.

A direct error argument and an error inside an array are observably different. On the recorded Excel build, MAP(NA(),LAMBDA(x,IFERROR(x,3))) returns #N/A before invoking the lambda, while MAP({#N/A},LAMBDA(x,3)) returns 3. The array element can reach the lambda even though the same error supplied directly stops the helper.

The result still needs space in the worksheet. A blocked spill can produce #SPILL!; it does not change the array calculation itself. Try it shows the array without placing it in a workbook.

A direct error stops these array functions; the same error in an array or cell is an element

An error written directly as an argument of these functions is the answer for the whole call. It is not placed in the result: HSTACK(1,#VALUE!) is #VALUE!, not a row holding 1 and an error, and TAKE(#N/A,0) is #N/A. With MAP the LAMBDA does not run at all: MAP(NA(),LAMBDA(xx,IFERROR(xx,3))) is #N/A. The same error inside an array, or in a referenced cell, is an ordinary element: MAP({#N/A},LAMBDA(xx,3)) is 3, and HSTACK(Data!C1,{1;2}) with #N/A in Data!C1 is a 2 by 2 array with #N/A in its first column. TOCOL and TOROW show the difference with ignore 2: TOCOL(#N/A,2) is #N/A, while TOCOL({#N/A},2) drops the error, has nothing left, and is #CALC!. EXPAND is an exception on the cell side: EXPAND(Data!C1,2,2,"pad") is #N/A for the whole call. BYROW and BYCOL check the direct error first too: BYROW(#N/A,#VALUE!) is #N/A, while BYROW({#N/A},2), where 2 is not a LAMBDA, is #VALUE!.

FormulaExcelMathematical value
=HSTACK(1,#VALUE!)
Excel 16.0.20527.20088 Current Channel, Windows 64-bit (NT 10.0.26200), x86-64, AMD Ryzen 7 4800H, en-ZA
Inputs and reference value

Typed formula.

#VALUE!—
=TAKE(#N/A,0)
Excel 16.0.20527.20088 Current Channel, Windows 64-bit (NT 10.0.26200), x86-64, AMD Ryzen 7 4800H, en-ZA
Inputs and reference value

Typed formula.

#N/A—
=MAP(NA(),LAMBDA(xx,IFERROR(xx,3)))
Excel 16.0.20527.20088 Current Channel, Windows 64-bit (NT 10.0.26200), x86-64, AMD Ryzen 7 4800H, en-ZA
Inputs and reference value

Typed formula.

#N/A—
=MAP({#N/A},LAMBDA(xx,3))
Excel 16.0.20527.20088 Current Channel, Windows 64-bit (NT 10.0.26200), x86-64, AMD Ryzen 7 4800H, en-ZA
Inputs and reference value

Typed formula.

3
0x4008000000000000
—
=HSTACK(Data!C1,{1;2})
Excel 16.0.20527.20088 Current Channel, Windows 64-bit (NT 10.0.26200), x86-64, AMD Ryzen 7 4800H, en-ZA
Inputs and reference value

Number supplied through a cell.

Data!C1: #N/A

{#N/A,1;#N/A,2}—
=TOCOL(#N/A,2)
Excel 16.0.20527.20088 Current Channel, Windows 64-bit (NT 10.0.26200), x86-64, AMD Ryzen 7 4800H, en-ZA
Inputs and reference value

Typed formula.

#N/A—
=TOCOL({#N/A},2)
Excel 16.0.20527.20088 Current Channel, Windows 64-bit (NT 10.0.26200), x86-64, AMD Ryzen 7 4800H, en-ZA
Inputs and reference value

Typed formula.

#CALC!—
=EXPAND(Data!C1,2,2,"pad")
Excel 16.0.20527.20088 Current Channel, Windows 64-bit (NT 10.0.26200), x86-64, AMD Ryzen 7 4800H, en-ZA
Inputs and reference value

Number supplied through a cell.

Data!C1: #N/A

#N/A—
=BYROW(#N/A,#VALUE!)
Excel 16.0.20527.20088 Current Channel, Windows 64-bit (NT 10.0.26200), x86-64, AMD Ryzen 7 4800H, en-ZA
Inputs and reference value

Typed formula.

#N/A—
=BYROW({#N/A},2)
Excel 16.0.20527.20088 Current Channel, Windows 64-bit (NT 10.0.26200), x86-64, AMD Ryzen 7 4800H, en-ZA
Inputs and reference value

Typed formula.

#VALUE!—

Inputs, build details and evidence

How to implement

Separate the last argument from the input arrays. Validate the callable and its parameter count without treating it as a displayed error. For a shared input shape, allocate that output shape and visit each coordinate. Read one value from each input at that coordinate, bind the lambda's parameters, evaluate its body and store the scalar result at the same coordinate.

Keep direct argument errors distinct from errors held in an array or referenced cell. Passing an array element through the lambda is necessary for formulas that deliberately replace errors. Likewise, preserve any callable carried inside an array value.

Test mismatched input dimensions, reference inputs, a lambda returning an array, and the order of calls to volatile expressions separately. A general array-broadcast rule is not sufficient evidence for MAP's shape rule. The recorded examples below settle the direct-error distinction; they do not settle every shape case.

Rust code

Show the CalcFunc source of this function

Quoted from the public repository DnaCalc/DnaCalc, crates calc-func and calc-fml, at commit 9e1884369a67. Comments are the source's own. A kernel shared with other functions appears once, on its module page.

MAP · 1 lines · calc-func/src/catalogue/lambda_helpers.rs on GitHub
1 map_fn "MAP" (2, 254) [R "array1", R "lambda_or_array2"] resume map_resume => map_task; |s, a, sv| { run(s, map_task(s, a, sv), sv) }
map_task · 33 lines · calc-func/src/catalogue/lambda_helpers.rs on GitHub
fn map_task(
    site: &Site<'_>,
    a: &[CalcValue],
    sv: &mut EvalServices<'_>,
) -> Step<Box<dyn KernelTask>> {
    // Fn2 roots031/034: a direct first-source error precedes even a valid LAMBDA.
    // Root035 keeps invalid-LAMBDA validation ahead of a later scalar source error.
    scalar_error(&a[0])?;
    let inputs = a.len() - 1;
    let mut sources = Vec::with_capacity(inputs);
    for index in 0..inputs {
        sources.push(prepared(site, a, index, sv)?);
    }
    let f = lambda(a, inputs, inputs)?;
    // Fn5 helper015: later whole-argument errors are invalid MAP sources.
    // Held errors and errors inside arrays still reach the LAMBDA (016/017).
    for value in &a[1..inputs] {
        if value.callable_value().is_none() && matches!(value.core_ref(), CoreRef::Error(_)) {
            return fail(W::Value);
        }
    }
    let lists: Vec<Vec<CalcValue>> = sources.iter().map(items).collect();
    let count = lists.iter().map(Vec::len).max().unwrap_or(1);
    let shape = sources
        .iter()
        .find_map(|source| source.as_array().map(CalcArray::shape))
        .filter(|shape| shape.rows * shape.cols == count)
        .unwrap_or(ArrayShape {
            rows: 1,
            cols: count.max(1),
        });
    Ok(helper(site, f, HelperInput::Map(lists), shape, count))
}

Kernels shared with other functions

Argument and result plumbing

No implementation has been published with a Handbook test suite for this function.

Version differences

Microsoft lists MAP for Microsoft 365 and Excel 2024 on Windows and Mac. The build-specific observations below concern error handling. They do not establish that older or later builds share every helper-function rule.

Excel 16.0.20527.20088

Windows 64-bit (NT 10.0.26200), x86-64, AMD Ryzen 7 4800H, en-ZA

=MAP(NA(),LAMBDA(xx,IFERROR(xx,3))) returned #N/A. =MAP({#N/A},LAMBDA(xx,3)) returned 3 (0x4008000000000000). Inputs were supplied through formula literals. These are controls from this environment, not a same-input comparison with another build.

Observed formulas and results
  • =MAP(NA(),LAMBDA(xx,IFERROR(xx,3))) → #N/A (formula-literal)
  • =MAP({#N/A},LAMBDA(xx,3)) → 3
    0x4008000000000000 (formula-literal)

Alternatives

Use an ordinary array expression for a simple elementwise calculation such as squaring. Use BYROW or BYCOL for whole-row or whole-column calculations. REDUCE carries one accumulator through the array; SCAN also returns the intermediate accumulators. MAKEARRAY generates values from row and column indices.

Named variants

No named variants are recorded yet.

Suggest a correction or contribute an implementation · For agents