cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Helper I
Helper I

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
Highlighted
Community Support
Community Support

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.

View solution in original post

2 REPLIES 2
Highlighted
Community Support
Community Support

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.

View solution in original post

Highlighted
Helper I
Helper I

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
Community Conference

Power Platform Community Conference

Check out the on demand sessions that are available now!

Power Platform ISV Studio

Power Platform ISV Studio

ISV Studio is designed to become the go-to Power Platform destination for ISV’s to monitor & manage published applications.

secondImage

Power Platform 2020 release wave 2 plan

Features releasing from October 2020 through March 2021

Tech Marathon

Maratón de Soluciones de Negocio Microsoft

Una semana de contenido con +100 sesiones educativas, consultorios, +10 workshops Premium, Hackaton, EXPO, Networking Hall y mucho más!

Top Solution Authors
Top Kudoed Authors
Users online (7,886)