cancel
Showing results for
Did you mean:
Highlighted

I'm wondering if someone has come across a solution to adding leading zeros to a number.
The idea is that I have an identifying number that is always 5 digits so the output I would like to see is:

• 00001 (original number 1)
• 00022 (original number 22)
• 00333 (original number 333)
• 04444 (original number 4444)

I can add leading zeros no problem with concat so if I add four zeros to the start (0000) the output I get is

• 00001
• 000022
• 0000333
• 00004444

How can I extract the substring from the right to a lenght of 5?

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
Super User III

Here is a Flow that runs successfully that I believe demonstrates what you are trying to accomplish.

Here is the formula that I am using for varLength:

length(variables('varStart'))

Here is the expression that I'm using for varResult:

substring(variables('varStart'),sub(variables('varLength'),5),5)

This solution should work regardless of how long you make the initial string.

Scott

If you like my response, please give it a Thumbs Up.

Scott
6 REPLIES 6
Highlighted
Super User III

Here is a Flow that runs successfully that I believe demonstrates what you are trying to accomplish.

Here is the formula that I am using for varLength:

length(variables('varStart'))

Here is the expression that I'm using for varResult:

substring(variables('varStart'),sub(variables('varLength'),5),5)

This solution should work regardless of how long you make the initial string.

Scott

If you like my response, please give it a Thumbs Up.

Scott
Highlighted
Anonymous
Not applicable

A couple quick thoughts...

Are you actually usings strings? I ask since you are using concat to pad zero's to the left.

One idea would be to only pad on the number of zero's you need?  You could do this by getting the lenght of the current string, then only concat w/ the number of zero's required.  That would negate the need for your question.

However, to answer your actual ask, could you not use the lenght of the string minus 5 for the "start" parameter of substring, and then you would get the last 5?  Too bad there isn't a left() or right() parallel in flow just yet.

Highlighted

Thank you for the quick reply. I gave it a go and its working perfectly. Appreciate the help!!

@Anonymous

Thanks for the repy! Interesting idea to find the length and then add the appropriate number of zeros. Would have been my backup plan if I couldn't get it done a more traditional way.

If anyone else is reading along I added a Uservoice to see if Left() and Right() can be added to the expressions list.

Have the expressions for Left() and Right()

Highlighted
Anonymous
Not applicable

Hey, in my world, if it aint broke, don't recode it! Thanks for reading it anyway!

I voted your left/right UV up as that would be nice, and surely isn't a huge stretch for them functionally.

Flow On!

Highlighted
Frequent Visitor

I agree: either a right(TEXT,LENGTH)-function or the option to make the second parameter to substring() negative would be so much more elegant.

Announcements

#### Super User Program Update

Three Super User rank tiers have been launched!

#### Power Platform 2020 release wave 2 plan

Features releasing from October 2020 through March 2021

#### New & Improved Power Automate Community Cookbook

We've updated and improved the layout and uploading format of the Power Automate Cookbook!

#### Power Automate Community User Group Member Badge

Fill out a quick form to claim your user group badge now!

Top Solution Authors
Top Kudoed Authors
Users online (8,155)