PowerApps Collection: Add, Update, Remove and Filter items

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.

Table of Contents  show

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.
add a record to PowerApps CollectionPowerApps Collection

Select Tablet layout under the Blank app section as shown in below.

MY LATEST VIDEOS!

add a record to Power Apps CollectionPowerApps Collection

In the Power Apps New Screen, Click on Insert tab and Select Label.

add item to collection powerappsPowerApps Collection

Add four Labels. Just rename all the Label names by double-clicking on it as like the below screenshot.

powerapps update collection itemPowerApps Collection example

In the same way, Click on Insert tab -> Text -> Select Text input.

powerapps remove item from collectionCreate PowerApps Collection

Add four Text inputs for four Labels. Remove the text input name from those text boxes.

powerapps add item to collectionHow to create a collection in PowerApps

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.

powerapps remove item from collectioncreate a collection in PowerApps

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.

powerapps remove item from collection not workingcreate a collection in PowerApps

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}

How to add item to PowerApps CollectionAdd items to a PowerApps collection

Now to see how the app works, Click on F5 or Preview icon from right top of the page.

powerapps remove last item from collectionAdd items to a PowerApps collection

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.

powerapps create collection on startAdd items to a PowerApps collection

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.

powerapps create collection on startpowerapps create collection on start
add records to PowerApps Collectionpowerapps create collection on start

When you add more items to Collections, then you can view all the items inside the Powerapps Collections as shown below.

Add records to Power Apps CollectionAdd records to PowerApps Collection

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).

How to remove an item from the Power Apps collectionremove an item from the PowerApps collection

Select the Collection name (CandidateInfo) from the Data source as shown below.

How to remove an item from the PowerApps collectionremove an item from PowerApps collection

Go to Gallery Properties from the right side of the page. Select the Gallery Layout as Title and subtitle.

remove an item from the PowerApps collectionHow to remove an item from the PowerApps collection

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.

remove an item from the Power Apps collection
remove items from the Power Apps collectionRemove item from PowerApps collection

Select the Gallery and click on the Edit icon on the top of the gallery as shown below.

powerapps remove selected item from collectionRemove item from PowerApps collection

Choose a Trash icon (Insert -> Icons).

remove item from the PowerApps collectionpowerapps remove single item from collection

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)
remove item from the Power Apps collectionpowerapps remove one item from collection

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)
How to remove items from the PowerApps collectionpowerapps remove selected item from collection

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.

powerapps remove first item from collectionpowerapps remove first item from collection

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.

remove items from Power Apps collectionremove items from Power Apps collection

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.

powerapps Update functionUpdate collection item in PowerApps

Take a Button (Insert -> Button) and rename it to Update Item.

power apps Update function

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
powerapps UpdateIf functionUpdate collection item in PowerApps

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.

powerapps update function exampleUpdate collection item in PowerApps

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.

how to use a filter in PowerApps CollectionPowerApps collection filter example

For that, Take a Gallery screen (Insert -> Gallery -> Vertical) in Power apps.

How to use a filter in Power Apps CollectionPowerApps collection filter

Select a Data Source (CandidateInfo) in your app.

use a filter in Power Apps CollectionHow to use filter in PowerApps Collection

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.

use a filter in PowerApps Collectionfilter in PowerApps Collection

In the Gallery Screen, You can see all records (Name and ID) that belong to Bangalore.

use filter in PowerApps Collectionfilter in PowerApps Collection

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.

How to use PowerApps collection row numberPowerApps collection row number

Add a Label (Insert -> Label).

How to get PowerApps collection row numberHow to get PowerApps collection row number

Seect the Label. To add a row number, put this below formula in the Label formula bar.

Text = ThisItem.Id

Where, Id = RowNumber

powerapps get value from collectionHow to get PowerApps collection row number

Now you can view your each item Id as like below screenshot.

get PowerApps collection row numberHow to get PowerApps collection row number

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.

get value from Power Apps Collectionget value from PowerApps Collection

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 “,” 
get value from PowerApps Collectionget value from PowerApps Collection

This below screeshot represents all the Candidate Names that retrieved by the above formula.

How to get value from Power Apps Collectionget value from PowerApps Collection

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 collectionPowerApps patch collection
  • 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"})
power apps patch collectionPowerApps patch collection example

When you will preview the app, then you can see these below two buttons.

powerapps patch functionPowerApps patch collection

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.

powerapps patch function syntaxHow to use PowerApps patch collection

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.

powerapps patch function to update recordpowerapps patch function to update record

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.

PowerApps Collection LookUpPowerApps Collection LookUp

Also, you may like the below Powerapps tutorials:

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.

原文地址:https://www.cnblogs.com/lingdanglfw/p/14873218.html