• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar

Tachytelic.net

  • Get in Touch
  • About Me

Add st, nd, rd and th (ordinal) suffix to a number in Power Automate

November 22, 2020 by Paulie 2 Comments

Sometimes you need to create an ordinal number for use in an email or similar situation. Power Apps does not have any support for this type of number formatting but it can be created quite easily with an expression.

The rules are as follows:

  • st is used for numbers ending in 1.
  • nd is used for numbers ending in 2
  • rd is used for numbers ending in 3
  • all other numbers end in th except…
  • Numbers ending in 11, 12, or 13 use th.

In Power Automate you can generate an ordinal number with the following expression:

if(endsWith(string(outputs('NumbeToConvert')),'12'),formatNumber(outputs('NumbeToConvert'), '#th'),
if(endsWith(string(outputs('NumbeToConvert')),'13'),formatNumber(outputs('NumbeToConvert'), '#th'),
if(endsWith(string(outputs('NumbeToConvert')),'1'),formatNumber(outputs('NumbeToConvert'), '#st'),
if(endsWith(string(outputs('NumbeToConvert')),'2'),formatNumber(outputs('NumbeToConvert'), '#nd'),
if(endsWith(string(outputs('NumbeToConvert')),'3'),formatNumber(outputs('NumbeToConvert'), '#rd'),
formatNumber(outputs('NumbeToConvert'), '#th')))))))

Where outputs(‘NumbeToConvert’) is the value you want to replace. An example flow using the above:

Image of a Power Automate Flow that creates an ordinal number.

The result is obviously 102nd:

Result of a Power Automate Expression that creates an ordinal number.

The flow simply uses the endswith function to determine the correct ordinal reference.

Hope this helps.

Filed Under: Power Platform Tagged With: Power Automate

Reader Interactions

Comments

  1. Jay says

    May 6, 2022 at 2:33 pm

    This will output 11st instead of 11th because 11 ends with 1 (your 3rd code line and first rule).
    I did it like this:

    if(and(greater(outputs(‘NumbeToConvert’),3),less(outputs(‘NumbeToConvert’),21)),formatNumber(outputs(‘NumbeToConvert’), ‘#th’),
    if(equals(outputs(‘NumbeToConvert’),1),formatNumber(outputs(‘NumbeToConvert’), ‘#st’),
    if(equals(outputs(‘NumbeToConvert’),2),formatNumber(outputs(‘NumbeToConvert’), ‘#nd’),
    if(equals(outputs(‘NumbeToConvert’),3),formatNumber(outputs(‘NumbeToConvert’), ‘#rd’),
    formatNumber(outputs(‘NumbeToConvert’), ‘#th’)))))

  2. Jay says

    May 6, 2022 at 2:38 pm

    oops! I mean:

    if(and(greater(variables(‘InfringementCount’),3),less(variables(‘InfringementCount’),21)),formatNumber(variables(‘InfringementCount’), ‘#th’),
    if(endsWith(string(variables(‘InfringementCount’)),’1′),formatNumber(variables(‘InfringementCount’), ‘#st’),
    if(endsWith(string(variables(‘InfringementCount’)),’2′),formatNumber(variables(‘InfringementCount’), ‘#nd’),
    if(endsWith(string(variables(‘InfringementCount’)),’3′),formatNumber(variables(‘InfringementCount’), ‘#rd’),
    formatNumber(variables(‘InfringementCount’), ‘#th’)))))

Leave a Reply Cancel reply

Primary Sidebar

Link to my LinkedIn Profile
Buy me a coffee
Image link to all Power Automate content

Excellent Power Automate Blogs

  • Damien Bird
  • Dennis (Expiscornovus)
  • Tom Riha

Subscribe to Blog via Email

Enter your email address to subscribe to this blog and receive notifications of new posts by email.

Join 245 other subscribers.

Go to mobile version