LAMBDA · Statistical
Count unique LAMBDA
xl.count.unique counts distinct values and ignores blanks. Austin, Dallas, Austin, Houston counts as 3.
Syntax =xl.count.unique(values)
=LAMBDA(values,
LET(
flat, UNIQUE(TOCOL(values, 1)),
ROWS(flat)
)
)Arguments
| Name | Required | What to pass |
|---|---|---|
| values | Required | A row or a column. Blanks are ignored. Text matching is not case-sensitive inside UNIQUE for this use only if the values differ only by case. UNIQUE is case-sensitive. |
Examples
Four cities, one repeated
=xl.count.unique(A1:A4)Result 3
| A | B | |
|---|---|---|
| 1 | Austin | |
| 2 | Dallas | |
| 3 | Austin | |
| 4 | Houston | |
| 5 | Distinct | 3 |
xl.count.unique counts Austin once. Austin, Dallas, Austin, Houston is 3. Blanks are dropped before the count, so an empty cell at the bottom of a column does not become its own category.
UNIQUE is case-sensitive. austin and Austin are two values. COUNTIF would have treated them as one. This function does not.
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.count.unique, 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.count.unique(...).
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
TOCOL with ignore flag 1 stacks the range and drops blanks. UNIQUE keeps the first of each remaining value. ROWS counts that list.
Limits
Errors are not ignored. A #N/A in the list makes the count fail. Numbers and text are both counted. 10 and the text “10” are different.