cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
Advocate I
Advocate I

Add Leading Zero's on Number Input

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
Super User III

@Eyerise:

 

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.

 

RightString1.jpgRightString2.jpgRightString3.jpg   

 

If this addresses your issue, please mark you post as Solved.

 

Scott

 

If I have answered your question, please mark your post as Solved.
If you like my response, please give it a Thumbs Up.

Scott

View solution in original post

7 REPLIES 7
Highlighted
Super User III
Super User III

@Eyerise:

 

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.

 

RightString1.jpgRightString2.jpgRightString3.jpg   

 

If this addresses your issue, please mark you post as Solved.

 

Scott

 

If I have answered your question, please mark your post as Solved.
If you like my response, please give it a Thumbs Up.

Scott

View solution in original post

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

@ScottShearer 

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

Highlighted

@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

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.

Highlighted

Sorry for hijacking the post. Hi Scott! I followed what you described here but I couldn't get working.


The value for the first "Initialize variable" was the SP list item ID from the trigger.

 

This is what I got.
Unable to process template language expressions in action 'Initialize_variable_3' inputs at line '1' and column '11411': 'The template language function 'substring' parameter is out of range: 'start index' must be non-negative integer and should be less than the length of the string.

Annotation 2020-08-20 113647.png

Helpful resources

Announcements
Community Conference

Power Platform Community Conference

Check out the on demand sessions that are available now!

Power Platform ISV Studio

Power Platform ISV Studio

ISV Studio is designed to become the go-to Power Platform destination for ISV’s to monitor & manage published applications.

Top Solution Authors
Top Kudoed Authors
Users online (7,353)