Remove and RemoveIf functions

Applies to: Canvas apps Model-driven apps Power Platform CLI

Removes records from a data source.

Note

PAC CLI pac power-fx commands do not support the RemoveIf function.

Description

Remove function

Use the Remove function to remove a specific record or records from a data source.

For collections, the entire record must match. You can use the RemoveFlags.All argument to remove all copies of a record; otherwise, only one copy of the record is removed.

RemoveIf function

Use the RemoveIf function to remove a record or records based on a condition or a set of conditions. Each condition can be any formula that results in a true or false and can reference columns of the data source by name. Each condition is evaluated individually for each record, and the record is removed if all conditions evaluate to true.

Remove and RemoveIf return the modified data source as a table. You can use both functions only in behavior formulas.

You can also use the Clear function to remove all of the records in a collection.

Delegation

When used with a data source, these functions cannot be delegated. Only the first portion of the data source will be retrieved and then the function applied. This may not represent the complete story. A warning may appear at authoring time to remind you of this limitation.

Delegation support (Experimental)

Delegation support for RemoveIf is now in Experimental Preview (default OFF) for data sources that support it. If a data source doesn't support this feature, Power Apps will send a query to the server and retrieve all data that matches the filter expression up to the maxium of either 500, 2000, or the data page size. Then, it will perform a delete operation on each of those records with individual calls to the server.

Syntax

Remove( DataSource, Record1 [, Record2, ... ] [, RemoveFlags.All ] )

  • DataSource – Required. The data source that contains the record or records that you want to remove.
  • Record(s) – Required. The record or records to remove.
  • RemoveFlags.All – Optional. In a collection, the same record may appear more than once. You can add the RemoveFlags.All argument to remove all copies of the record.

Remove( DataSource, Table [, RemoveFlags.All ] )

  • DataSource – Required. The data source that contains the records that you want to remove.
  • Table – Required. A table of records to remove.
  • RemoveFlags.All – Optional. In a collection, the same record may appear more than once. You can add the RemoveFlags.All argument to remove all copies of the record.

RemoveIf( DataSource, Condition [, ... ] )

  • DataSource – Required. The data source that contains the record or records that you want to remove.
  • Condition(s) – Required. A formula that evaluates to true for the record or records to remove. You can use column names from the DataSource in the formula. If you specify multiple Conditions, all must evaluate to true for the record or records to be removed.

Examples - single formulas

In these examples, you'll remove a record or records in a data source that's named IceCream and that starts with the data in this table:

IceCream example.

Create a collection with sample records

To create a collection with this data:

  1. Insert a Button control.

  2. Set button control's OnSelect property to the below formula:

    ClearCollect( IceCream,
                  { ID: 1, Flavor: "Chocolate",  Quantity: 100 },
                  { ID: 2, Flavor: "Vanilla",    Quantity: 200 },
                  { ID: 3, Flavor: "Strawberry", Quantity: 300 }
    )
    
  3. Select the button while holding down the Alt key:

Remove sample records from collection using a formula

Formula Description Result
Remove( IceCream,
LookUp( IceCream, Flavor="Chocolate" ))
Removes the Chocolate record from the data source. Result with Vanilla and Strawberry.

The IceCream data source has been modified.
Remove( IceCream,
LookUp( IceCream, Flavor="Chocolate" ), LookUp( IceCream, Flavor="Strawberry" ) )
Removes two records from the data source. Result with only Vanilla.

The IceCream data source has been modified.
RemoveIf( IceCream, Quantity > 150 ) Removes records that have a Quantity that's greater than 150. Result with only Chocolate.

The IceCream data source has been modified.
RemoveIf( IceCream, Quantity > 150, Left( Flavor, 1 ) = "S" ) Removes records that have a Quantity that's greater than 150 and Flavor starts with an S. Result with Chocolate and Vanilla.


The IceCream data source has been modified.
RemoveIf( IceCream, true ) Removes all records from the data source. Result with no IceCream.

The IceCream data source has been modified.

In this example, you'll use a Gallery control to list the records in a table. And then use the Remove function to selectively remove an item.

Prepare for sample data

This example uses the Contacts table in Microsoft Dataverse available with the sample apps and data. You can deploy sample apps and data when you create an environment. You can also use any other data source instead.

In this example, you'll remove an item by using a button that is outside the gallery.

  1. Create a new blank canvas app using a Phone layout.

    A blank canvas app using the phone layout.

  2. Select the Insert from the left pane.

  3. Select Vertical gallery.
    A Gallery control is be added to your screen.

    Using the Insert tool pane to add a vertical gallery control.

  4. You're prompted to select a data source where you can select a data source from the available data sources.
    For example, select the Contacts table to use sample data:

    Selecting the Contacts table to display in the gallery.

    The gallery shows items from this table:

    Gallery added showing the Contacts table.

  5. Insert a Button control from left pane:

    Using the Insert tool pane to add a button control.

  6. Move the added button below the gallery items:

    Move button.

  7. Update button text property to Remove record. You can also use text of your choice:

    Rename button.

  8. Set the OnSelect property for this button control to the following formula:

    Remove( Contacts, Gallery1.Selected )
    

    Setting the OnSelect property of the button control.

    The gallery control makes the currently selected record available using Selected property. Remove function refers to this selected record to remove it.

  9. Preview the app using the Play button on the top right, or press F5 on keyboard:

    Preview app.

  10. Select a record to remove, such as Nancy's record in this example:

    Select a record.

  11. Select Remove record:

    Gallery of contacts, now without the Nancy record that has been removed.

    Selecting the button removes the selected record (in this example, Nancy's record).

  12. Close the app preview.

    Tip

    You can also use alternate behavior with Alt key instead of using the app preview with Play button or F5.

In this example, you'll remove an item by using an icon placed inside the gallery.

Create a collection with sample data

If you already have prepared sample data, skip this step and move to Trash can icon inside a gallery.

  1. Add a Button control to your screen.

  2. Set the OnSelect property to the following formula:

    ClearCollect( SampleContacts,
          { 'Full Name': "Yvonne McKay (sample)",      'Primary Email': "someone_a@example.com" },
          { 'Full Name': "Susanna Stubberod (sample)", 'Primary Email': "someone_b@example.com" },
          { 'Full Name': "Nancy Anderson (sample)",    'Primary Email': "someone_c@example.com" },
          { 'Full Name': "Maria Campbell (sample)",    'Primary Email': "someone_d@example.com" },
          { 'Full Name': "Robert Lyon (sample)",       'Primary Email': "someone_e@example.com" },
          { 'Full Name': "Paul Cannon (sample)",       'Primary Email': "someone_f@example.com" },
          { 'Full Name': "Rene Valdes (sample)",       'Primary Email': "someone_g@example.com" }
    )
    
  3. Select the button while holding down the Alt key.

Sample collection is created that you can use in the following example.

  1. Create a new blank canvas app using a Phone layout.

    A blank canvas app using the phone layout.

  2. Select the Insert from the left pane.

  3. Select Vertical gallery.
    A Gallery control is be added to your screen.

    Using the Insert tool pane to add a vertical gallery control.

  4. You're prompted to select a data source where you can select a data source from the available data sources.
    For example, select the Contacts table to use sample data:

    Selecting the Contacts table to display in the gallery.

    If you created a collection, select your collection instead:

    Sample contacts collection.

  5. Select a control within the top item in the gallery.

    To ensure next step inserts item into gallery's template and not outside the gallery, ensure you follow this step before moving to the next step.

    Select top record in a gallery.

  6. Select Add icon from left pane.

    Using the Insert tool pane to add an icon control.

    Note

    Add icon inserts a + icon on the left side of the gallery, replicated for each item in the gallery.

  7. In the top item, move the icon to the right side of the screen.

    Move icon.

  8. Select the Icon property for icon and set it to the following formula to update the icon image as trash icon:

    Icon.Trash
    

    Note

    The Icon. prefix is only shown when you're actively editing the formula.

    Changing the icon to the trash can icon.

  9. Set the OnSelect property to the following formula:

    Remove( [@Contacts], ThisItem )
    

    Note

    You must use global disambiguation operator [@...] in this example with sample data that uses the Contacts table to avoid conflict with a One-to-Many relationship. If you use data sources such as a list or a SQL Server table, using global disambgulation operator is not required.

    OnSelect for trash icon.

  10. Preview the app using the Play button on the top right, or press F5 on keyboard.

  11. Select the trash icon next to a record, for example Maria's:

    Gallery with one of the contacts removed.

    The record is deleted:

    Deleted record.

  12. Close the app preview.