Skip to main content

Notifications

Power Automate - Building Flows
Answered

Replace last letter of Variable with the next in sequence

(0) ShareShare
ReportReport
Posted on by 252

Hi,

 

I am curious. I have a variable XXX C0006A.  Is it possible to resubmit the variable and change the A to B, XXX C0006B in a flow?

 

Then Change to a C if required.

  • Skybluekid Profile Picture
    Skybluekid 252 on at
    Re: Replace last letter of Variable with the next in sequence

    Thank you both for the assistance

  • Verified answer
    Chriddle Profile Picture
    Chriddle 7,305 on at
    Re: Replace last letter of Variable with the next in sequence
    concat(
    	slice('XXX C0006A', 0 , -1),
    	chunk('ABCDEFGHIJKLMNOPQRSTUVWXYZ', 1)[
    		add(indexOf('ABCDEFGHIJKLMNOPQRSTUVWXYZ', last('XXX C0006A')), 1)
    	]
    )
  • Skybluekid Profile Picture
    Skybluekid 252 on at
    Re: Replace last letter of Variable with the next in sequence

    Hi @grantjenkins 

     

    Thank you for the reply.  I would not anticipate that it would get to Z, in the case of the actual flow.  I will give this a try.

  • grantjenkins Profile Picture
    grantjenkins 11,057 on at
    Re: Replace last letter of Variable with the next in sequence

    A few questions.

    1. What do you do with XXX C0006Z - what should it change to?
    2. Will the variable always be in the same format? Will it always be the last letter you need to change?

    Below is one way to do it.

     

    See full flow below. I'll go into each of the actions. Note that they are all Compose action - I've just renamed them.

    grantjenkins_0-1698674460078.png

     

    The expression I used in the Output is:

    concat(
     substring(outputs('Input'), 0, sub(length(outputs('Input')), 1)), 
     substring(outputs('AZ'), add(indexOf(outputs('AZ'), last(outputs('Input'))), 1), 1)
    )

     

    Note that in AZ I added A at the end so if the code ends with Z it will be set as A. Not sure what you would want to do in your scenario.

  • Skybluekid Profile Picture
    Skybluekid 252 on at
    Re: Replace last letter of Variable with the next in sequence

    Hi @fchopo 

    thank you for the reply.  I was thinking more changing the letter dynamically i.e. if the variable contains XXX C0006A, then it would automatically change to XXX C0006B, without any hardcoding.

  • fchopo Profile Picture
    fchopo 7,968 on at
    Re: Replace last letter of Variable with the next in sequence

    Hi @Skybluekid 

    You could use the following expression:

    replace(outputs('compose'),last(outputs('compose')),'B')

    compose.png

     Hope that helps!

    Ferran

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Microsoft Kickstarter Events…

Register for Microsoft Kickstarter Events…

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Announcing Forum Attachment Improvements!

We're excited to announce that attachments for replies in forums and improved…

Leaderboard

#1
WarrenBelz Profile Picture

WarrenBelz 145,445

#2
RandyHayes Profile Picture

RandyHayes 76,287

#3
Pstork1 Profile Picture

Pstork1 64,741

Leaderboard