cancel
Showing results for
Did you mean:

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

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
9 REPLIES 9
Super User

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
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.

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()

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!

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.

Frequent Visitor

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.

formatNumber(triggerBody()?['TheColumnThatHasYourNumber'], '00000')

Throw in whatever reference has the number you want to add leading zeros to.

Kudo Collector

@catpigeon This is the correct answer. The post is a few years old now, but if @Eyerise is still active, it could be worth updating this thread and accepting this solution. Kudos to @catpigeon this works brilliantly.

Announcements

Power Platform Connections Ep 14 | J. Panchal | Thursday, 18 May 2023

Episode Fourteen of Power Platform Connections sees David Warner and Hugo Bernier talk to Microsoft PM Jocelyn Panchal, alongside the latest news, videos, product reviews, and community blogs.     Use the hashtag #PowerPlatformConnects on social media for a chance to have your work featured on the show.      Show schedule in this episode:  00:00 Cold Open 00:32 Show Intro 01:10 Jocelyn Panchal Interview 24:10 Blogs & Articles 29:50 Outro & Bloopers  Check out the blogs and articles featured in this week’s episode:   https://www.nathalieleenders.com/Blog/index.php/;focus=STRATP_com_cm4all_wdn_Flatpress_42136159&path=?x=entry:entry230511-101930#C_STRATP_com_cm4all_wdn_Flatpress_42136159__-anchor  @NathLeenders https://www.keithatherton.com/posts/2023-05-12-msbuild2023-cloud-skills-challenge/  @MrKeithAtherton https://elliskarim.com/2023/05/13/how-to-find-files-in-onedrive-that-match-a-naming-pattern/  @MrCaptainKarim https://www.linkedin.com/pulse/my-fond-memories-scottish-summit-2022-pranav-khurana/ @pranavkhuranauk https://www.linkedin.com/feed/update/urn:li:activity:7061777660745560064/?updateEntityUrn=urn%3Ali%3Afs_feedUpdate%3A%28V2%2Curn%3Ali%3Aactivity%3A7061777660745560064%29  @thevictordantas  Action requested: Feel free to provide feedback on how we can make our community more inclusive and diverse.  This episode premiered live on our YouTube at 12pm PST on Thursday 18th May 2023.  Video series available at Power Platform Community YouTube channel.  Upcoming events:  Power Apps Developers Summit – May 19-20th - London European Power Platform conference – Jun. 20-22nd - Dublin Microsoft Power Platform Conference – Oct. 3-5th - Las Vegas  Join our Communities:  Power Apps Community Power Automate Community Power Virtual Agents Community Power Pages Community  If you’d like to hear from a specific community member in an upcoming recording and/or have specific questions for the Power Platform Connections team, please let us know. We will do our best to address all your requests or questions.

Announcing | Super Users - 2023 Season 1

Super Users – 2023 Season 1    We are excited to kick off the Power Users Super User Program for 2023 - Season 1.  The Power Platform Super Users have done an amazing job in keeping the Power Platform communities helpful, accurate and responsive. We would like to send these amazing folks a big THANK YOU for their efforts.      Super User Season 1 | Contributions July 1, 2022 – December 31, 2022  Super User Season 2 | Contributions January 1, 2023 – June 30, 2023    Curious what a Super User is? Super Users are especially active community members who are eager to help others with their community questions. There are 2 Super User seasons in a year, and we monitor the community for new potential Super Users at the end of each season. Super Users are recognized in the community with both a rank name and icon next to their username, and a seasonal badge on their profile.  Power Apps  Power Automate  Power Virtual Agents  Power Pages  Pstork1*  Pstork1*  Pstork1*  OliverRodrigues  BCBuizer  Expiscornovus*  Expiscornovus*  ragavanrajan  AhmedSalih  grantjenkins  renatoromao    Mira_Ghaly*  Mira_Ghaly*      Sundeep_Malik*  Sundeep_Malik*      SudeepGhatakNZ*  SudeepGhatakNZ*      StretchFredrik*  StretchFredrik*      365-Assist*  365-Assist*      cha_cha  ekarim2020      timl  Hardesh15      iAm_ManCat  annajhaveri      SebS  Rhiassuring      LaurensM  abm      TheRobRush  Ankesh_49      WiZey  lbendlin      Nogueira1306  Kaif_Siddique      victorcp  RobElliott      dpoggemann  srduval      SBax  CFernandes      Roverandom  schwibach      Akser  CraigStewart      PowerRanger  MichaelAnnis      subsguts  David_MA      EricRegnier  edgonzales      zmansuri  GeorgiosG      ChrisPiasecki  ryule      AmDev  fchopo      phipps0218  tom_riha      theapurva  takolota     Akash17  momlo     BCLS776  Shuvam-rpa     rampprakash  ScottShearer     Rusk  ChristianAbata     cchannon  Koen5     a33ik  Heartholme     AaronKnox  okeks      Matren  David_MA     Alex_10        Jeff_Thorpe        poweractivate        Ramole        DianaBirkelbach        DavidZoon        AJ_Z        PriyankaGeethik        BrianS        StalinPonnusamy        HamidBee        CNT        Anonymous_Hippo        Anchov        KeithAtherton        alaabitar        Tolu_Victor        KRider        sperry1625        IPC_ahaas      zuurg    rubin_boer   cwebb365   Dorrinda   G1124   Gabibalaban   Manan-Malhotra   jcfDaniel   WarrenBelz   Waegemma   drrickryp   GuidoPreite   metsshan    If an * is at the end of a user's name this means they are a Multi Super User, in more than one community. Please note this is not the final list, as we are pending a few acceptances.  Once they are received the list will be updated.

Check out the new Power Platform Communities Front Door Experience!

We are excited to share the ‘Power Platform Communities Front Door’ experience with you!   Front Door brings together content from all the Power Platform communities into a single place for our community members, customers and low-code, no-code enthusiasts to learn, share and engage with peers, advocates, community program managers and our product team members. There are a host of features and new capabilities now available on Power Platform Communities Front Door to make content more discoverable for all power product community users which includes ForumsUser GroupsEventsCommunity highlightsCommunity by numbersLinks to all communities Users can see top discussions from across all the Power Platform communities and easily navigate to the latest or trending posts for further interaction. Additionally, they can filter to individual products as well.   Users can filter and browse the user group events from all power platform products with feature parity to existing community user group experience and added filtering capabilities.     Users can now explore user groups on the Power Platform Front Door landing page with capability to view all products in Power Platform.      Explore Power Platform Communities Front Door today. Visit Power Platform Community Front door to easily navigate to the different product communities, view a roll up of user groups, events and forums.

Microsoft Power Platform Conference | Registration Open | Oct. 3-5 2023

We are so excited to see you for the Microsoft Power Platform Conference in Las Vegas October 3-5 2023! But first, let's take a look back at some fun moments and the best community in tech from MPPC 2022 in Orlando, Florida.   Featuring guest speakers such as Charles Lamanna, Heather Cook, Julie Strauss, Nirav Shah, Ryan Cunningham, Sangya Singh, Stephen Siciliano, Hugo Bernier and many more.   Register today: https://www.powerplatformconf.com/

Top Solution Authors
Top Kudoed Authors
Users online (2,190)