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

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Automate / Split Text String Base...
Power Automate
Unanswered

Split Text String Based on Conditions

(0) ShareShare
ReportReport
Posted on by 53

In Power Automate I want to take output values from a previous step that is listed like 405, 402, 518 and transpose it vertically without the comma.  If the output value says "All" then return the string "All".  If the output value only has one number and no commas like 405 then just return 405.

 

Can someone demonstrate how I can achieve this?

 

Thanks!

Categories:
I have the same question (0)
  • bshoyat Profile Picture
    24 on at

    Hello, you can do this using the split function. For example, if you have your previous step be a compose named value. You can do the following in the next action:

    split(outputs(‘value’), ‘,’)

     

    that should do exactly what you are asking. 

  • coolbeans23 Profile Picture
    53 on at

    That does not take into account the other conditions though like "All" and the single number like 405

  • bshoyat Profile Picture
    24 on at

    Ohh okay so when it’s a single item you don’t want an array. So what you can do is something like this:

    EDITED:

    if(equals(length(split(outputs('value'),',')),1),outputs('value'),split(outputs('value'),',')).

    i apologize if I missed a coma or a parenthesis as I don’t have power automate open. 

     

    @coolbeans23 , I apologize i was missing somehting in that. I have updated it now and it works on my end. One thing to note, if your previous action has "405, 507, 420", you will end up with

    ["405",

    " 507",

    " 420"]

    The best way i can think to remove that is by including a replace function like this:

    if(equals(length(split(outputs('value'),', ')),1),outputs('value'),split(replace(outputs('value'),' ',''),',')).
     
    Let me know if you have other questions.
  • coolbeans23 Profile Picture
    53 on at

    The flow failed with the error:  'The template language function 'if' expects three parameter..... 

  • coolbeans23 Profile Picture
    53 on at

    If you take a closer look there is a space before the second and third number.  I tried using the trim function in my formula:

    split(trim(triggerBody()['text']),',')  but it resulted in the same thing below:

     

    ["405",

    " 507",

    " 420"]

     

    How can I remove those spaces before the numbers? Is it a non-breaking space?

  • bshoyat Profile Picture
    24 on at

    @coolbeans23,

    use this

    if(equals(length(split(outputs('value'),', ')),1),outputs('value'),split(replace(outputs('value'),' ',''),','))

  • grantjenkins Profile Picture
    11,063 Moderator on at

    Hopefully this is what you're looking for. It depends on exactly what you want if there is more than one item - so added a few variations.

     

    Initialize variable contains your data.

    grantjenkins_0-1677987062310.png

     

    Select uses the following expressions to extract out each of the items including trimming any spaces.

    //From
    split(variables('data'), ',')
    
    //Map
    trim(item())

    grantjenkins_1-1677987167493.png

     

    Below are three different variations depending on what you're looking for.

     

    Option 1: Join with new line character

     

    This option would use a Join action to join the items with a new line character.

    //From
    body('Select')
    
    //Join with
    decodeUriComponent('%0A')

    grantjenkins_2-1677987564621.png

     

    Option 2: Join with </br> tag (will split the data in any HTML output including email)

     

    This option would use a Join action to join the items with a </br> tag.

    //From
    body('Select')
    
    //Join with
    <br>

    grantjenkins_3-1677987583079.png

     

    Option 3: Output as array of items, or if one item, a single item

     

    This option uses a Compose with the following expression.

    if(equals(length(body('Select')), 1), first(body('Select')), body('Select'))

    grantjenkins_4-1677987636820.png

     

     

    Examples using the numbers "405, 402, 518" for Join New Line, Join BR, and Compose respectively.

    grantjenkins_11-1677987973766.png

    grantjenkins_12-1677987985554.png

    grantjenkins_13-1677988005081.png

     

    Examples using the numbers "405" for Join New Line, Join BR, and Compose respectively.

    grantjenkins_14-1677988021496.png

    grantjenkins_10-1677987933704.png

    grantjenkins_15-1677988043179.png

     

    Examples using the numbers "All" for Join New Line, Join BR, and Compose respectively.

    grantjenkins_16-1677988092086.png

    grantjenkins_17-1677988109150.png

    grantjenkins_18-1677988131636.png


    ----------------------------------------------------------------------
    If I've answered your question, please mark the post as Solved.
    If you like my response, please consider giving it a Thumbs Up.

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

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Automate

#1
Michael E. Gernaey Profile Picture

Michael E. Gernaey 501 Super User 2025 Season 2

#2
Tomac Profile Picture

Tomac 323 Moderator

#3
abm abm Profile Picture

abm abm 237 Most Valuable Professional

Last 30 days Overall leaderboard