cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
srizvi
Level: Powered On

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

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

1 ACCEPTED SOLUTION

Accepted Solutions
Community Support Team
Community Support Team

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

Hi @srizvi,

 

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 Support Team _ Kris Dai
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
2 REPLIES 2
Community Support Team
Community Support Team

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

Hi @srizvi,

 

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 Support Team _ Kris Dai
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
srizvi
Level: Powered On

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

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

Helpful resources

Announcements
firstImage

Watch Sessions On Demand!

Continue your learning in our online communities.

Power Platform 2019 release wave 2 plan

Power Platform 2019 release wave 2 plan

Features releasing from October 2019 through March 2020

FirstImage

Power Platform World Tour

Coming to a city near you

thirdimage

PowerApps Community User Group Member Badge

Fill out a quick form to claim your user group badge now!

FourthImage

Join PowerApps User Group!!

Connect, share, and learn with your peers year-round

SecondImage

Power Platform Summit North America

Register by September 5 to save $200

Top Kudoed Authors
Users Online
Currently online: 227 members 4,474 guests
Please welcome our newest community members: