Concat And ForAll In PowerApps

In this blog, we will see difference between Concat and ForAll functions in PowerApps and how to use them.

In this blog, we will see the difference between Concat and ForAll functions of PowerApps. If you want to understand the difference between Concat and Concatenate functions, then have a look at my  blog.
 
Example
 
Let's take a real-time scenario, with the help of which, we will understand the difference between Concat and ForAll functions.
 
As a part of the business process, you need to collect a table of records from end-users using PowerApps forms/screens; you need to store this information and show it back to the user whenever needed. So, how would you do that? How would you store the table of records in SharePoint or SQL DB for that matter (whatever is data source)?
 
Solution 
 
You need to follow the below steps to fulfill the above requirement:
  1. Collect the data using Gallery control in PowerApps
  2. Combine the data from gallery items into one long string with delimiter used
  3. Store it in SharePoint multiline text column or SQL table column
  4. While showing it back to the user, read the string and do operations on a string to create a collection variable
  5. Bind collection variable to Gallery
Now, let's see where and how we need to use Concat and ForAll in the above steps.
 
In Step 2 of the above process, we need to use the Concat function.
  1. Concat(OrginalList ,Concatenate("Title-", Title, ";Status-",Status, "#"))  
First Parameter - OriginalList – this is the source (collection object) bound to Gallery control. You directly provide Gallery.Item here.
 
Second Parameter - Operation you want to do on each record of the data source.
 
Output
 
This function returns operation output after executing it for all the records in the source collection.
 
 
So, as you can see in the below screen, using Concat function, I am able to convert tabular data/collection/gallery records into one string.
 
 
In Step 4 of the above process we need to use ForAll function
  1. ForAll(Split(MultilineTextColFromSP.Text,"#"),      
  2. Collect(NewCollection1,      
  3. {Title: Text(Last(FirstN(Split(Result,";").Result,1).Result).Result),    
  4. Status:Text(Last(FirstN(Split(Result,";").Result,2).Result).Result)}))    
First Parameter
 
Collection object --  in our example we are splitting the long string using delimiter which returns a collection object.
 
Second Parameter
 
The logic which you want to run on the individual record - in our example, we are splitting the string further to get individual column values and collecting the record into a collection.
 
Output
 
It executes the logic on the records of the source and returns a table/collection.
 
 
As you can see below, using ForAll function we are able to convert a string into the collection and bind it to Gallery control.
 
 
That’s it for this blog. Hope this helps.