In this PowerApps tutorial, We will discuss how to add an item to PowerApps Collection, how to remove an item from the PowerApps collection, how to update collection items in PowerApps.
Also, We will see the uses of a filter in PowerApps Collection, Get PowerApps collection row number, Get value from Power Apps Collection, Power Apps Patch Collection, and PowerApps collection Lookup.
How to add a record to PowerApps Collection
To add a new single record or multiple records to Powerapps Collection, follow the below processes.
- Sign in the PowerApps app with your credentials.
- Go to Apps option from the left navigation.
- Select Canvas under the + New app tab from the top of the page.
Select Tablet layout under the Blank app section as shown in below.
MY LATEST VIDEOS!
In the Power Apps New Screen, Click on Insert tab and Select Label.
Add four Labels. Just rename all the Label names by double-clicking on it as like the below screenshot.
In the same way, Click on Insert tab -> Text -> Select Text input.
Add four Text inputs for four Labels. Remove the text input name from those text boxes.
Go to the left navigation of the screen. Double-click any Text input name and rename it. Repeat it for all rest of the three inputs.
Add a Button (go to Insert tab -> Button). Double-click on the button and rename this button text to Add item To Collection as shown below.
Click on Button and apply the below button formula to add an item into collections.
OnSelect = Collect(CandidateInfo, {Name:I_Name.Text,Id:I_ID.Text,MobileNumber:I_Mob.Text,Address:I_Address.Text})
Here, {I_Name, I_ID, I_Mob and I_Address = Name of the Text inputs}
Now to see how the app works, Click on F5 or Preview icon from right top of the page.
Enter Candidate Name, Candidate ID, Mobile Number, and Address in the input fields. Click on Add Item To Collection button. This button behavior will not affect anything when you will click on the button.
To view the adding item in Collections, Go to View tab -> Collections as like the below screenshot.
Click on the collection name (CandidateInfo), you can view the added item as shown below.
When you add more items to Collections, then you can view all the items inside the Powerapps Collections as shown below.
This is how to create a collection in PowerApps and also we saw how to add an item to a PowerApps collection.
You may like PowerApps LastSubmit() with Examples.
How to remove an item from the PowerApps collection
If you want to remove the unnecessary items from the Powerapps Collections, then do the below processes:
Go to Insert tab -> Gallery -> Vertical(Select any gallery from the drop-down).
Select the Collection name (CandidateInfo) from the Data source as shown below.
Go to Gallery Properties from the right side of the page. Select the Gallery Layout as Title and subtitle.
Click on the vertical Gallery and put the below formula:
Items = CandidateInfo
Where, CandidateInfo= Collection name
When you will put the above formula, then you can see all the items that you have added in the Powerapps collection.
Select the Gallery and click on the Edit icon on the top of the gallery as shown below.
Choose a Trash icon (Insert -> Icons).
When you will add a Trash icon to the Gallery, then the icon will affect all the rows that are present in the Gallery. That means the icon will add in each item row automatically.
To remove an item from the Powerapps Collections, Select a Trash icon and put the below formula in the formula bar as:
OnSelect = Remove(CandidateInfo, ThisItem)
Similarly, Add a Button and rename it to Clear Item. This button is used to clear all the items that are present in the Powerapps Collections.
Select the button (Clear Item) and put the below formula in the formula bar:
OnSelect = Clear(CandidateInfo)
Now to remove an item from the Powerapps Collection, click on any trash icon of an item. Then that item will be removed from the Gallery as well as Powerapps Collections.
Similarly, To remove all the items from the Powerapps collections, click on the Clear Item button. Then all the items will remove from the Gallery as well as Powerapps Collections.
This is how to remove an item from the PowerApps collection.
How to Update collection item in PowerApps
In the Powerapps Update Function, you can use two different functions as:
- Update: Powerapps Update Function is used to replace the entire record in a data source.
- UpdateIf: Powerapps UpdateIf Function is used to modify one single or more values in one or more records that match one or more conditions.
Syntax: PowerApps Update Function
Update( DataSource, OldRecord, NewRecord [, All ] )
Where,
- DataSource = This contains all the records that you want to replace. It may be a Table, Collections, etc.
- OldRecord = It is the record that you want to replace.
- NewRecord = It is the replacement record. This is not a change record. Here, the entire record is replaced.
- All = Mention the All argument to remove all copies of the record.
Syntax: PowerApps UpdateIf Function
UpdateIf( DataSource, Condition1, ChangeRecord1 [, Condition2, ChangeRecord2, ... ] )
Where,
- DataSource = This data source contains one or more records that you want to modify.
- Condition(s) = In this condition, you can use column names of DataSource in the formula. It evaluates to True for the record that you want to modify.
- ChangeRecord(s) = You can provide a change record of new property values that satisfy the condition.
Example:
In this below example, I want to update the address of all records that are present in the Powerapps Collections. You can see all the records in the below screenshot.
Take a Button (Insert -> Button) and rename it to Update Item.
Select the button and appy the below update formula as shown below:
OnSelect = UpdateIf(CandidateInfo, Name = Name, {Address:I_Address.Text})
Where,
- OnSelect = Property Name
- UpdateIf = Function Name
- CandidateInfo = Collection Name
- Name = Text input name
- Address = Text input name
In the Preview app, When you will click on the Update Item button, then the address will change in each record in the Powerapps Collections.
This way, we can update collection items in PowerAPps.
How to use a filter in PowerApps Collection
Powerapps Filter function is used to findout the specific records in a table which satisfies a formula.
PowerApps Filter Function Syntax
Filter( Table, Formula1 [, Formula2, ... ] )
- Where,
- Filter = Function Name
- Table = Particular Table to search
- Formula(s) = It specifies the formula of a specific record of the table. If you apply more than one formula, the results of all formulas are combined with the And function.
Example: PowerApps Filter Function
In the beow screenshot, you can see there are some records in the Powerapps app.
From these below records, I am going to filter some specific data that belongs to Bangalore.
For that, Take a Gallery screen (Insert -> Gallery -> Vertical) in Power apps.
Select a Data Source (CandidateInfo) in your app.
Select the Gallery and apply the below Filter formula into it:
Items = Filter(CandidateInfo, Address="Bangalore")
Where,
- Filter = Function Name
- CandidateInfo = Collection Name
- Address = Field Name
- Bangalore = Filter Value
Not only Address, But also, you can filter any field as like Name, Id, Mobile Number etc.
In the Gallery Screen, You can see all records (Name and ID) that belong to Bangalore.
This is how to use a filter in PowerApps Collection.
How to use PowerApps collection row number
Suppose in the Power apps Collection Gallery app, you want to add a row number to each item.
PowerApps collection row number Syntax
Text = ThisItem.RowNumber
Where,
- Text = Label Name
- RowNumber = Put any Id, Name or any Identification number Column that you want to display
Example PowerApps collection row number
The below screenshot represents a Powerapps gallery that contains these below items. To use the row number to each and every item, Select the whole Gallery and click on the Edit icon as shown below.
Add a Label (Insert -> Label).
Seect the Label. To add a row number, put this below formula in the Label formula bar.
Text = ThisItem.Id
Where, Id = RowNumber
Now you can view your each item Id as like below screenshot.
This is how we can get row number in PowerApps collection
How to get value from PowerApps Collection
Similarly, To get the values from Powerapps Collections, do these below things.
Add a Label (Insert -> Label) in your Powerapps Screen.
Select the Label and put the below formula in the Label formula bar:
Text = Concat(CandidateInfo, Name, ", ")
Where,
- Text = Label Name
- Concat = Function Name
- CandidateInfo = Powerapps Collection Name
- Name= It returns all the Name (Here you can use any field name that you want to view according to your requirement as like Id, Address, etc.)
- “, ” = It is a Delimiter which separates the name by using a “,”
This below screeshot represents all the Candidate Names that retrieved by the above formula.
This how to get value from PowerApps collection.
PowerApps patch collection
PowerApps Patch Function is used to create or modify single or more records in the data source. For simple changes in the data source, you can use this Patch function.
By using this Patch function, the values of a specific field will modify without affecting other properties.
Lets take an example, Suppose a collection have the below records.
- Employee Name
- Employee ID
- Employee Mobile Number
- Employee Address
Here, Suppose you want to change only the Mobile Number of a specific Employee, then in this case, you can use this Patch function.
PowerApps Patch Function Syntax
Now, we will see how to use patch function in PowerApps.
Modify or create a record in a data source
Patch( DataSource, BaseRecord, ChangeRecord1 [, ChangeRecord2, … ])
Where,
- DataSource = It contains all the records that you want to modify or a record that you want to create. Simply, you need to take a Table or any Collection Name.
- BaseRecord = It is used to modify or create the record. If the record is coming from a data source, then the record is modified. If the result is used as Default, then the record is created.
- ChangeRecord(s) = It is used to one or more records that contain properties to modify in the BaseRecord.
Modify or create a set of records in a data source
Patch( DataSource, BaseRecordsTable, ChangeRecordTable1 [, ChangeRecordTable2, … ] )
Where,
- DataSource = It contains all the records that you want to modify or a record that you want to create. Simply, you need to take a Table or any Collection Name.
- BaseRecord = It is used to modify or create the record. If the record is coming from a data source, then the record is modified. If the result is used as Default, then the record is created.
- ChangeRecordTable(s) = It is used to one or more tables of records that contain properties to modify for each record of the BaseRecordTable.
Example
In this below example, there are two buttons on the Powerapps screen. Those two buttons are:
- Add Items To Powerapps Collection: This button helps to add the new records in the Powerapps Collections.
Take a Button (Insert -> Button). Rename the Button, Select it and apply the below formula to add records in the Powerapps Collections.
OnSelect = ClearCollect(ProductList,{Name:"Mobile",Colour:"Blue"},{Name:"Tv",Colour:"Black"},{Name:"Tablet",Colour:"Grey"})
ClearCollect is used to clear all the records from the Powerapps Collections and add a new record into it.
- Powerapps Patch Collection: This button helps to modify a specific value of a specific record in the Powerapps Collection.
Take a Button (Insert -> Button). Rename the Button, Select it and apply the below formula to modify a particular value of a particular record in the Powerapps Collections.
Patch(ProductList,First(Filter(ProductList,Colour="Blue")),{Name:"Soundbox"})
When you will preview the app, then you can see these below two buttons.
First, Click on Add Items To Powerapps Collection button and go to the Collections (View -> Collections). You can see all the new records that are added to the Collections.
When you will click on the Powerapps Patch Collection button, then the first item Name value will modify where the Color is Blue.
Instead of Mobile, it will change to Soundbox as shown below.
This is how to use PowerApps patch collection.
PowerApps Collection LookUp
The LookUp function helps to find a record (first record) in a table that satisfies a formula. You can use the LookUp function to find a single record that matches one or more criteria.
PowerApps LookUp Function Syntax
LookUp( Table, Formula [, ReductionFormula ] )
- Where,
- LookUp = Function Name
- Formula = It specifies the formula by which each record of the table is evaluated
- ReductionFormula = It specifies the formula of a record that was found. It helps to reduce the record to a single value. The function returns the full record from the table if you don’t use this formula.
Example: Power Apps LookUp Function
- Add a Label (Insert -> Label) in your Power apps Screen.
- Select the Label and put the below formula in the Label formula bar:
Text = LookUp(CandidateInfo, Id ="121", Name )
Where,
- LookUp = Function Name
- CandidateInfo = Collection Name
- Id, Name = Collection Field Name
Instead of Id and Name, you can take any Collection field values as like (Address, Mobile Number).
Here, In the below screenshot, you can see the Candidate Name whose Id value is 121.
Also, you may like the below Powerapps tutorials:
- Create a Data Table from Excel Data using Power Apps
- How to share PowerApps with external users
- Create PowerApps App for SharePoint List
- PowerApps show hide fields based on Yes/No column
- PowerApps update data table columns
- How to use PowerApps Table() Function
- PowerApps Functions Tutorial
- Export PowerApps from one Tenant to another Tenant
- How to display images from a SharePoint Online library in PowerApps
In this PowerApps Collection Tutorial, We discussed how to add an item to PowerApps Collection, How to remove an item from the PowerApps collection, How to Update collection items in PowerApps.
Also, We saw the uses of a filter in PowerApps Collection, Get the PowerApps collection row number, Get value from Power Apps Collection, Power Apps Patch Collection, and PowerApps collection Lookup.