LAMBDA · Dynamic arrays

Unpivot LAMBDA

xl.unpivot turns a crosstab into rows of row label, column label, and value. Austin and Dallas across 2024 and 2025 become four rows.

Microsoft 365, Excel 2024, and Excel for the web. Excel 2021 does not have LAMBDA.

Syntax =xl.unpivot(row_headers, col_headers, data)

xl.unpivot
=LAMBDA(row_headers, col_headers, data,
  LET(
    r, ROWS(data),
    c, COLUMNS(data),
    i, SEQUENCE(r * c),
    HSTACK(
      INDEX(row_headers, INT((i - 1) / c) + 1),
      INDEX(col_headers, MOD(i - 1, c) + 1),
      INDEX(data, INT((i - 1) / c) + 1, MOD(i - 1, c) + 1)
    )
  )
)

Arguments

NameRequiredWhat to pass
row_headersRequiredA one-column list, one label per data row.
col_headersRequiredA one-row list, one label per data column.
dataRequiredThe numbers, without the headers.

Examples

Two cities and two years

=xl.unpivot(A2:A3, B1:C1, B2:C3)

Result Four rows: 2024 Austin 10, 2024 Dallas 20, 2025 Austin 12, 2025 Dallas 22.

=xl.unpivot(A2:A3,B1:C1,B2:C3)E2
Wide
ABCDEFG
1AustinDallasYearCityAmount
2202410202024Austin10
3202512222024Dallas20
42025Austin12
52025Dallas22
A picture of the sheet, not a live calculator. The spill is E2:G5. Reading goes across each year, then down.

xl.unpivot turns a crosstab into a list. Years run down the side. Cities run across the top. The four numbers become four rows, read across 2024 and then across 2025: 2024/Austin/10, 2024/Dallas/20, 2025/Austin/12, and 2025/Dallas/22.

SUMIFS and a chart want that list. A PivotTable wants the crosstab. This LAMBDA is the bridge from the second shape to the first.

Add it to the workbook

Copy the formula in the block above, including the line breaks. Choose Formulas, Name Manager, New. Set the name to xl.unpivot, the scope to Workbook, and paste into Refers to. Excel Labs can do the same step: open the Advanced Formula Environment, add that name, and save it back to the workbook. A cell then calls =xl.unpivot(...).

The name needs Microsoft 365, Excel 2024, or Excel for the web. Excel 2021 returns #NAME? for LAMBDA even when it already has XLOOKUP, FILTER, or LET.

How it works

SEQUENCE counts from 1 through rows times columns. Integer division by the column count picks the row. The remainder picks the column. INDEX reads the row label, the column label, and the value at that intersection. HSTACK spills the three columns.

For a 2 by 2 block the positions are (1, 1), (1, 2), (2, 1), and (2, 2). That is across, then down.

Limits

The headers are not inside the data. Include them and the first value will be a label. Blank cells in the data are still emitted. Drop them afterward if a blank should not be a row.