LAMBDA · Text

Ordinal LAMBDA

xl.ordinal turns 1, 2, 3, and 4 into 1st, 2nd, 3rd, and 4th. 11, 12, and 13 stay 11th, 12th, and 13th. 21 is 21st.

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

Syntax =xl.ordinal(n)

xl.ordinal
=LAMBDA(n,
  LET(
    last_two, MOD(ABS(n), 100),
    last_one, MOD(ABS(n), 10),
    suffix, IF(AND(last_two>=11, last_two<=13), "th",
      SWITCH(last_one, 1, "st", 2, "nd", 3, "rd", "th")),
    n & suffix
  )
)

Arguments

NameRequiredWhat to pass
nRequiredA whole number. A fraction is not rounded. 21.9 becomes 21.9st if the units digit is 1, so pass an integer.

Examples

The teens and the twenties

=xl.ordinal(21)

Result 21st

=B1&IF(AND(MOD(B1,100)>=11,MOD(B1,100)<=13),"th",SWITCH(MOD(B1,10),1,"st",2,"nd",3,"rd","th"))B2
Ordinal
AB
1Number21
2Ordinal21st
A picture of the sheet, not a live calculator.

xl.ordinal adds the English suffix. 1 is 1st, 2 is 2nd, 3 is 3rd, and 4 is 4th. The teens are the trap: 11 is 11th, not 11st. 21 goes back to 21st because the last two digits are 21, not 11.

Use it on a ranked list or a day of the month. Pass a whole number. The function does not round. ROMAN labels the same 60 as LX. The ordinal for 60 is 60th.

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.ordinal, 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.ordinal(...).

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

MOD of 100 isolates the last two digits. If those are 11, 12, or 13, the suffix is th. Otherwise SWITCH on the last digit picks st, nd, rd, or the default th. The number is concatenated with the suffix, so the result is text.

Limits

Zero becomes 0th. Negatives use the absolute value for the suffix test and keep the minus sign in the text, so -1 becomes -1st. That is rarely what a ranking wants. Reject negatives before you call it.