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 / Unable to remove last ...
Power Automate
Answered

Unable to remove last character from String Variable

(0) ShareShare
ReportReport
Posted on by Microsoft Employee

My flow is grabbing the work days for each user in a SPO List.

For each workday, I add it to a variable like this.

Sun,Mon,Tues,Weds

 

When I add it to the variable, I am using a comma at the end.

 

So when it gets posted to the SPO list, it actually looks like this:  Sun,Mon,Tues,Weds,

I am trying to remove the last comma, but it is not working.

Towards the end of my flow before I update the SPO item, I have a compose that is supposed to remove that last character.

I am using the same compose for another variable, and it is working fine.

substring(variables('vAssignmentDay'), 0, sub(length(variables('vAssignmentDay')), 1))
 
Any idea why it is not removing that last trailing comma?

 

 

Categories:
I have the same question (0)
  • Expiscornovus Profile Picture
    33,874 Most Valuable Professional on at

    Hi @lardo5150,

     

    Your expression looks fine. Can you show a screenshot of the values used in the flow instance which failed? Maybe there is a trailing space character which you don't see?

     

    If you want to be sure you could also use a lastindexof in your expression:

    substring(variables('vAssignmentDay'), 0, lastIndexOf(variables('vAssignmentDay'), ','))

     

     

  • lardo5150 Profile Picture
    Microsoft Employee on at

    So, it does not error, everything runs perfectly, I am just left with that trailing comma 🙂

    lardo5150_0-1643903488044.png

    FYI, as I show you this, keep in mind I was copying code from some of my other flows, so the Compose is most likely not needed but I just kept it anyways.

    We check to see if the variable vSunday is equal to zero (Monday is 1, Tuesday is 2, etc.)

    if it is, we do a compose (again, most likely not needed but I kept it as I was doing a copy to clipboard on everything).

    concat('Sun')
     
    We then add that output to the variable with a comma (I just checked, there is no space after the comma).
     
    lardo5150_1-1643903684268.png

     

    We do this for each day, checking if they are working that day, and add it to the variable the same each time, with a comma at the end.

     

  • Expiscornovus Profile Picture
    33,874 Most Valuable Professional on at

    Hi @lardo5150,

     

    Thanks for your explanation. I am a bit confused, to be honest 😁.

     

    Do you have that substring function to clean up the trailing comma in your current flow setup? If so, where in the flow is that located? I assume after the last append to string variable action?

     

    Btw, another approach could be to create an array of working days and using a join function to turn it into a comma separated string value. With this approach you don't have to worry about a trailing delimiter.

  • lardo5150 Profile Picture
    Microsoft Employee on at

    That is a good idea.  I will see if I can rework this later on.

    For the time being, if we can get the trailing comma to drop that would be great.

    and yes, the compose of removing the trailing comma is at the end.

     

    lardo5150_0-1643905277391.png

     

  • Expiscornovus Profile Picture
    33,874 Most Valuable Professional on at

    Hi @lardo5150,

     

    Can you share a screenshot of your AssignmentDays column setttings in SharePoint. It is a choice field (which allows the selection of multiple values?), correct?

     

    I will create a sample for you with a join function 🙂

  • lardo5150 Profile Picture
    Microsoft Employee on at

    Yes, but the way it was designed is not user friendly (I did not build up the SPO site, I just have to work with it).

    So I am doing the same thing for AssignmentDays and AssignmentHours.  they are both choice columns.

    Hours start at 0 up to 23 (military).

    Days starts at 0 (Sunday) to 6.

     

    So I am created a single line text column next to them and am putting the more user friendly values there.

    You can see I did the QueueTime and the trailing comma was removed.  Not sure why it did not work for the work days as everything is the same.

     

    lardo5150_0-1643906075339.png

     

  • Verified answer
    Expiscornovus Profile Picture
    33,874 Most Valuable Professional on at

    Hi @lardo5150,

     

    Below is an example of a join function to turn an array (choice field with multiple selections) into a comma separated string value.

     

    1. Use a Select to retrieve the labels of the selected values of the AssignmentDays field.

     

    2. In the update item action an expression is used in the WorkDays field to join these values from the select with a comma delimiter:

     

     

     

    join(body('Select'), ',')

     

     

     

     

    workingdays_join.png

     

    The end result should look something like this.

    testing_workingdays.png

     

    In your setup you probably can use a couple of nested replace functions instead of the item()['Value'] in the Select action. It looks a bit quirky, but it should work.

     

     

     

    replace(replace(replace(replace(replace(replace(replace(item()['Value'], '0', 'Sun'), '1', 'Mon'), '2', 'Tues'), '3', 'Weds'), '4', 'Thurs'), '5', 'Fri'), '6', 'Sat')

     

     

     

     

    nestedreplacefunctions.png

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Users!

Kudos to our 2025 Community Spotlight Honorees

Congratulations to our 2025 community superstars!

Congratulations to the April Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Automate

#1
Vish WR Profile Picture

Vish WR 976

#2
Valantis Profile Picture

Valantis 863

#3
Haque Profile Picture

Haque 547

Last 30 days Overall leaderboard