web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Automate / Expression Builder - G...
Power Automate
Answered

Expression Builder - Get last 6 characters of a string

(1) ShareShare
ReportReport
Posted on by 5
Im using Power Automate Desktop - Signed into a personal account (Not a business account)

I'm copying text to a variable and I'd like to get the last 6 characters of that text and copy to a seperate Variable
Example
Variable1 = Description of goods (Code:13453)

I want to get the "(Code:13453)" and put into a different variable.
Have been using the "Get Subtext" action to try get this done.  At the "Character Position", have tried creating an expression but everything I'm trying is giving error messages.

Have been using copilot and chatgpt to get this done but they are no help.
 
Troubleshooting so far.
I've managed to figure out that %Variable1.Length% gives me the correct number of characters in that variable.

(Copilot's solutions) - All giving error messages = Arguement "CharacterPosition" must be an integer value
%Variable1.Length& -12
%Variable1.Substring(Variable1.Length - 12)%
%Variable1.Subtext(Variable1.Length - 12)%

Would anyone know the correct expression needed to get this done.
Cannot find a list of valid expressions I can use in Power Automate on the web, so have been trying to use different languages I've used in the past, but none are working.
even the Right() function isn't valid.
 
I have the same question (0)
  • Verified answer
    eetuRobo Profile Picture
    4,565 Super User 2026 Season 1 on at
    The syntax would be: %Variable1.Length -12%



    Or you could also use Parse text -action with RegEx enabled. So this retrieves text from the first parenthesis. So from the text: Description of goods (Code:13453)
    It returns the (Code:13453)


    Either way works but regex one can be more reliable if the text is not always in the exact same format so if there is some extra characters at the end for example then the subtext might not give correct value.
  • David_MA Profile Picture
    14,956 Super User 2026 Season 1 on at
    I don't think you meant to ask about getting the last six characters, but if you did, this expression should do the trick:
     
    if(lessOrEquals(length(string(variables('Variable1'))), 5), 'Error', substring(string(variables('Variable1')), sub(length(string(variables('Variable1'))), 6), 6))
     
    This is what it will return:
     
    If you don't want the closing parentheses, use this expression:
     
    if(lessOrEquals(length(string(variables('Variable1'))), 5), 'Error', substring(string(variables('Variable1')), sub(length(string(variables('Variable1'))), 6), 5))
     

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

Season of Sharing Community Challenge Launch!

Jump in, show your community spirit, and win prizes!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Congratulations to the May Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Automate

#1
Valantis Profile Picture

Valantis 377

#2
11manish Profile Picture

11manish 279

#3
David_MA Profile Picture

David_MA 234 Super User 2026 Season 1

Last 30 days Overall leaderboard