Delete multiple records in PowerApps using Remove function

Microsoft PowerApps simplifies app creation with templates, connectors, and third-party apps. Its popularity among developers is due to its ability to perform CRUD operations and support most data sources, including on-premises. This article describes how to delete multiple records in PowerApps using Remove function.

Problem

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

how to delete all the employees belonging to a department using Remove function when the user clicks the ‘Delete All’ button in a department grid.

Solution : Delete multiple records in PowerApps using Remove function

1. Open the PowerApps canvas app in edit mode.

2. Select ‘Delete All’ button and click on Advanced properties on right side pane.

3. Use the below expression on the ‘OnSelect’ property.

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 Employees to be Deleted

The first line of code utilizes the Collect function to create a collection named collect_employees_tobe_deleted. This collection will store the employee records that belong to the department specified by the var_department_id variable.

Here’s the breakdown of the Collect function:

  • collect_employees_tobe_deleted: This is the name of the collection to be created.
  • Filter('employee', department_id = Value(var_department_id)): This is the filtering criteria used to select the employees to be deleted. It filters the 'employee' table based on the department_id field, selecting only the records where department_id matches the value of the var_department_id variable.

Remove Selected Employees

The second line of code utilizes the ForAll function to iterate through the collect_employees_tobe_deleted collection and remove each employee record from the 'employee' table.

Here’s the breakdown of the ForAll function:

  • collect_employees_tobe_deleted As A: This defines the variable A that will hold each employee record from the collect_employees_tobe_deleted collection as it iterates through the collection.
  • Remove('employee', LookUp('employee', employee_id= A.employee_id));: This line removes the employee record corresponding to the employee_id value of the current A variable from the 'employee' table. The LookUp function retrieves the employee record based on the employee_id value.

In summary, this code first collects all employees belonging to the specified department and then removes each of those employees from the 'employee' table. This effectively removes all employees from the specified department from the data source.

Pro tips:
1. If you want to migrate your PowerApps canvas app from one environment to another, you can refer to this article.

See more

Kunal Rathi

With over a decade 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.
I am always interested in new challenges so if you need consulting help, reach me at kunalrathi55@gmail.com.

Shopping Cart
Scroll to Top