Quick answer: To delete multiple records from a Power Apps data source based on a condition, you can use RemoveIf. For more complex scenarios, such as collecting records first and deleting them one by one, ForAll with Remove can be used.

Problem

Let’s take an example of an employee and department table.

Power Apps employee and department data example

How can we delete all employees belonging to a department when the user clicks the Delete All button?

Power Apps Delete All button for multiple employee records

Solution: Delete multiple records in Power Apps

For a conditional delete, Microsoft recommends the RemoveIf function. It removes records from a data source when the specified condition is true.

Select the Delete All button and use the following expression in its OnSelect property:

RemoveIf('employee', department_id = Value(var_department_id))

This removes the employee records whose department_id matches the selected department.

Using ForAll and Remove

If your scenario requires collecting the records first, you can use the following approach:

Collect(
    collect_employees_tobe_deleted,
    Filter('employee', department_id = Value(var_department_id))
);

ForAll(
    collect_employees_tobe_deleted As A,
    Remove('employee', LookUp('employee', employee_id = A.employee_id))
);

Collect stores the matching records in a collection. ForAll then iterates over that collection, and Remove deletes the corresponding record from the data source.

Pro tips:
For large datasets, check the delegation behavior of your data source before using RemoveIf. Microsoft notes that unsupported delegation can cause Power Apps to retrieve only a limited number of matching records and delete them individually.

If you want to migrate a Power Apps canvas app between environments, refer to this guide.

See more

Visual Studio Marketplace

SSIS Catalog Migration Wizard

Extend Visual Studio with an easy way to migrate SSIS Catalog projects.

Kunal Rathi

With over 15 years of experience in data engineering and analytics, I've assisted countless clients in gaining valuable insights from their data. As a dedicated supporter of Data, Cloud and DevOps, I'm excited to connect with individuals who share my passion for this field. If my work resonates with you, we can talk and collaborate.