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 Apps / How to Concatenate() i...
Power Apps
Answered

How to Concatenate() inside a ForAll loop.

(0) ShareShare
ReportReport
Posted on by 3,347

This is a simple example, and I'm sure there are better ways to do it, but when this gets more complex, I will be needing to append to the end of a string every 'loop' of the ForAll().  Not quite sure how to do that since I'm not able to set a variable inside of it.  Or, is there a way?

 

 

 

Set(TestList,[12345,12346,12347,12348,12350,12351]);

Set(TestString,"Test");
ClearCollect(Testdcollect,(ForAll(TestList.Value, Concatenate("Text",Text(Value))
 )))

 

 

Desired result for this example is:

 

TestList = "12345,12346,12347,12348,12350,12352,12354,13000"

 

My end-all desired is:

 

TestList = "12345-12348, 12350, 12352-12354, 13000"


Thanks,
Rod

Categories:
  • cds Profile Picture
    1,001 on at

    try Concat instead of Concatenate

  • martinav Profile Picture
    3,347 on at

    @cds ,

     

    Ok, its that simple??  I'll try.  I keep forgetting there are more than one command for this.

  • timl Profile Picture
    37,287 Super User 2026 Season 2 on at

    @martinav 

    Rather then call the Concatenate function, could you accomplish what you want to carry out by calling Concat on your collection, and not using ForAll()?

    Set(TestString,
     Concat(TestList, Text(Value) & " ")
    )
  • Mitanshu Profile Picture
    1,658 Moderator on at

    happyume_0-1630440780368.png


    Set(
    TestString,
    Concat(TestList,ThisRecord.Value&",")
    );

    This will give you your initial desired state, although you will have to remove the last comma.

     

    Please click Accept as solution if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If this post or my previous reply was useful in other ways, please consider giving it Thumbs Up.

  • martinav Profile Picture
    3,347 on at

    @timl ,

     

    I tried to explain that yes, there are simpler ways to do this not using the ForAll().  I'm trying to understand the mechanics of doing it that way so I can do a much more complex operation.  Indicated by my "end-all" goal shown in my first post.

  • martinav Profile Picture
    3,347 on at

    @happyume ,

     

    Like I was just explaining to @timl , I need the ForAll() because I will be doing a conditional statement on EVERY item in the array in order to append something else to my text string.  Yes, your method works.  But it will not work to reach my "end-all" goal shown in my initial post. 

     

    I need to step through each item in the array, and append every loop.

  • timl Profile Picture
    37,287 Super User 2026 Season 2 on at

    Thanks @martinav for clarifying that - did you add the desired and "end-all" examples, or did I completely miss that when I originally read your post?!

  • martinav Profile Picture
    3,347 on at

    @timl ,

     

    Actually, people picked up on this QUICK!  I added that right after I submitted it.  I thought I did it quick enough to not be confusing.  But... nope!

     

    Sorry about that.  Your not going nuts.  I am!


    Rod

  • timl Profile Picture
    37,287 Super User 2026 Season 2 on at

    Thanks @martinav - I'm glad I'm not going nuts! The "end-all desired" result is quite tough to accomplish and I'm not sure right now how to approach this.

     

    To work around the problem of not being able to set variables from inside ForAll, the typical pattern is to store your workings and other values in a second collection by calling Collect, and to then process the second collection. My post here demonstrates this technique.

    https://powerusers.microsoft.com/t5/Building-Power-Apps/Building-a-string-within-ForAll/m-p/121976

     

    With the example you give, you would want to set/reset a variable or carry out some action when you discover that 12349 doesn't exist, and the challenge here is that ForAll isn't strictly a looping construct, and it doesn't operate sequentially either.

     

    I'll update this post if anything springs to mind and in the meantime, hopefully someone else might be able to come up with some other suggestions.

  • Verified answer
    Community Power Platform Member Profile Picture
    Microsoft Employee on at

    @martinav 

    This is a really interesting challenge ... and I like those 🙂

     

    I expanded on @timl idea of a collection and think I have a solution for you:

     

    // set up your list of values
    Set(TestList,[1,2,3,7,8,9,20,10,5,4]);
    
    // clear the collection before ForAll
    Clear(colTestList);
    
    
    ForAll( 
     // sorting the list of values makes sure you can add more values in any order without error
     Sort(TestList, Value,Ascending) As Count,
    
     // build collection of first and second values
     If( 
     // create first row in collection
     CountRows(colTestList)= 0 , Collect( colTestList, { FirstCol: First(TestList).Value, SecondCol: First(TestList).Value}),
     
     // update collection rows or add new ones as required
     Count.Value = Last( colTestList).SecondCol+1,
     Update(colTestList, Last(colTestList), {FirstCol: Last(colTestList).FirstCol ,SecondCol: Count.Value}),
     Collect(colTestList, { FirstCol: Count.Value, SecondCol: Count.Value}
     )
     )
    )

     

    Add a label and add this to the Text property

    Concat( colTestList, 
     FirstCol & 
     If( FirstCol = SecondCol, "," ,"-" & SecondCol & ",")
    )

    Your output will be;

    1-5,7-10,20,

     

    You can then use string manipulation to make it look how you like eg remove the finally comma, etc

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 Winners!

Congratulations to our community stars!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Congratulations to the July Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Apps

#1
11manish Profile Picture

11manish 394 Super User 2026 Season 2

#2
Mohsin Ali Profile Picture

Mohsin Ali 328

#3
WarrenBelz Profile Picture

WarrenBelz 324 Most Valuable Professional

Last 30 days Overall leaderboard