LAMBDA · Statistical
Text mode LAMBDA
xl.text.mode returns the text that appears most often. In Yes, No, Yes, Yes the mode is Yes. MODE.SNGL only does this for numbers.
Syntax =xl.text.mode(values)
=LAMBDA(values,
LET(
keys, UNIQUE(TOCOL(values, 1)),
counts, MAP(keys, LAMBDA(k, COUNTIF(values, k))),
INDEX(keys, MATCH(MAX(counts), counts, 0))
)
)Arguments
| Name | Required | What to pass |
|---|---|---|
| values | Required | The text values. Blanks are ignored. A tie returns the value UNIQUE lists first. |
Examples
Three Yes answers and one No
=xl.text.mode(A1:A4)Result Yes
| A | B | |
|---|---|---|
| 1 | Yes | |
| 2 | No | |
| 3 | Yes | |
| 4 | Yes | |
| 5 | Mode | Yes |
xl.text.mode is the most common answer on a survey of words. Yes, No, Yes, Yes returns Yes. MODE.SNGL cannot see text. It returns #N/A when every number is unique, and it never counts Yes.
A tie is not announced. The answer that appears first in the list wins, because that is the first key UNIQUE emits and MATCH stops at the first maximum.
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.text.mode, 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.text.mode(...).
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 drops blanks. UNIQUE lists each remaining answer once. MAP and COUNTIF count them. MATCH of the largest count returns the position, and INDEX returns the answer.
Limits
COUNTIF is not case-sensitive, so YES and Yes are the same answer. Numbers are counted too, if you mix them in. The function returns one value, not every tied value.