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 / Build string using a l...
Power Apps
Answered

Build string using a loop and pass the string as a parameter to the Table() function

(0) ShareShare
ReportReport
Posted on by Microsoft Employee

I want to build a string in the format required by the Table function.

 

 

This string will build uniquely for the current user facing record.

 

Note: Below code is rough draft. I need to accomplish something along those lines using Powerapps.

 

//Code

Set(BuildString, "");

Set(CurrentIndex, 0);

Set(TestString, "a,b,c,d");

Set(OccurancesOfDelimiter, ....); //Also need a way to retrieve occurances of a character in a TestString

Set(Counter, 0); DoUntil(OccurancesOfDelimiters, Set(Counter, Counter + 1); Set(CurrentValue, Mid(TestString, CurrentIndex, Find(",", TestString) - 1)); Set(BuildTable, BuildTable&"{Text:" &Char(34)&CurrentValue&Char(34)&","&"Val:"&Counter&"}"&", ") Set(CurrentIndex, Find(",", TestString, CurentIndex + 1)) ); Set(BuiltTable, Table(BuildTable))

There are two things I need from Powerapps to accomplish this.

 

1.) Find occurance of a character in a string. e.x For String x = "a,b,c,d"; If i did an operation to find how many occurances of commas there exists on X, then the return value should be 3.

 

2.) A way to loop X amount of times

 

3.) To be able to build a string and it pass as a parameter to Table() function.

 

Appreciate the help. 

 

- Syed

Categories:
I have the same question (0)
  • Verified answer
    v-xida-msft Profile Picture
    Microsoft Employee on at

    Hi @Anonymous,

     

    Could you please share a bit more about your scenario?

     

    For your first question, do you want to retrieve the occurances of commas existed on a string (e.g "a,b,c,d")?

     

    If you want to retrieve the occurances of commas existed on a string (e.g "a,b,c,d"), I think the Split function could achieve your needs. I have made a test on my side, please take a try with the following workaround:1.JPG

     

    In order to retrieve the number of commas existed within a string, set the Text property of the Label control to following formula:

    CountRows(Split(TextInput1.Text,","))-1

    On your side, you should type the following formula:

    CountRows(Split(TestString,","))-1

    Note: The TextString represents the String X that you mentioned.

     

    For your second question, do you want to loop the character separated via a comma within the TestString (X)? 

     

    If you want to loop the character separated via a comma within the TestString (X), I think the ForAll function (the only way to achieve a loop within PowerApps currently) could achieve your needs.

     

    More details about ForAll function in PowerApps, please check the following article:

    ForAll function

     

    For your third question, do you want to build a string (e.g. {Text: "a", Val:1} ) using a loop and psss it as a parameter to Table() function?

     

    In addition, If you want to achieve your needs using Table function, I afraid that there is no way to achieve your needs within PowerApps currently. Because the Set(Counter, Counter + 1) formula could not invoked within the ForAll function.

     

    As an alternative solution, you could consider take a try to use a Collection to achieve your needs instead of Table function. I have made a test on my side, please take a try with the following workaround:2.JPG

     

    Set the OnSelect property of the "Build String" button to following formula:

    Clear(TestString);
    ForAll(
    Split(TextInput1.Text,","),Collect(TestString,{Text:Result,Val:CountRows(TestString)+1})
    )

    On your side, you should type the following formula:

    Clear(TestString);
    ForAll(
    Split(X,","),Collect(TestString,{Text:Result,Val:CountRows(TestString)+1})
    )

    Note: The X represents the variable X that you mentioned.

     

     

    Best regards,

    Kris

     

     

  • Community Power Platform Member Profile Picture
    Microsoft Employee on at

    Thanks Kris!

     

    I did not know the Split function parsed a string into a table of strings, Result. This works perfectly with the ForAll function. I tried your solution on my end and it works. I marked your post as the solution.

     

    - Syed

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
WarrenBelz Profile Picture

WarrenBelz 345 Most Valuable Professional

#2
11manish Profile Picture

11manish 207 Super User 2026 Season 2

#3
Mohsin Ali Profile Picture

Mohsin Ali 177

Last 30 days Overall leaderboard