cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Ali_Nawaz
Helper III
Helper III

Delete Multiple records in SQL from powerapps

Hi powerUsers, 

I want to delete multiple records present in SQL on a single button click. 
Couldn't find any expression so far. 

looking forward to usual helpful and swift response. 


Best Regards, 
Ali Nawaz

1 ACCEPTED SOLUTION

Accepted Solutions

Hi @Ali_Nawaz ,

Do you want to remove multiple records from your SQL Table based on specific "Worker Number" , 'PayperiodStart" , 'PayperiodEnd" value?

 

Based on the needs that you mentioned, I think the RemoveIf function could achieve your needs. You could consider add a Text Input box (TextInput1) and two DatePicker controls (StartDatePicker & EndDatePicker) in your app.

 

I have made a test on my side, please consider take a try with the following workaround:

Set the OnSelect property of the "Remove" button:

RemoveIf(
         '[dbo].[YourSQLTable]',
         'Worker Number' = TextInput1.Text && Text(PayperiodStart, "yyyymmdd") = Text(StartDatePicker.SelectedDate, "yyyymmdd") && Text(PayperiodEnd, "yyyymmdd") = Text(EndDatePicker.SelectedDate, "yyyymmdd")
)

 

In addition, as an alternative solution, you could also consider add a Gallery within your app to list all avaiable records from your SQL Table. Then add a Checkbox control (Checkbox1) within the Gallery. If you want to remove the specific item, please check the corresponding Checkbox within the Gallery for specific item.

Outside, the Gallery, add a "Remove" button, set the OnSelect property to following:

ForAll(
       RenameColumns(Filter(Gallery1.AllItems, Checkbox1.Value = true), "ID", "ID1"),
       Remove('[dbo].[YourSQLTable]', LookUp('[dbo].[YourSQLTable]', ID = ID1))
)

Note:  I assume that the "ID" is a Primary Key column in your SQL Table.

 

Best regards,

Community Support Team _ Kris Dai
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

7 REPLIES 7
mdevaney
Super User III
Super User III

@Ali_Nawaz 

My choice would be the REMOVEIF function.

 

Here's a usage example.  It assumes you already have a Collection of the records you want to delete called your_collection_name and has unique identifier in the ID column.

RemoveIf(
    your_sql_datasource_name,
    ID in your_collection_name[@ID]
)

 

Link to MS Official Docs

https://docs.microsoft.com/en-us/powerapps/maker/canvas-apps/functions/function-remove-removeif

 

---
Please click "Accept as Solution" if my post answered your question so that others may find it more quickly. If you found this post helpful consider giving it a "Thumbs Up."

I have an SQL Table and all the entries in that table has unique IDs. 

How can I bulk delete those records ?

I want to delete records on the basis of specific  "Worker Number" , 'PayperiodStart" , 'PayperiodEnd". 
All records which have same values in these three columns must be deleted on a single button click. 

Looking forward to your earliest response. 

Best Regards. 

@Ali_Nawaz 

How many records in that SQL table of yours?

There could be 20-30 records at once

@Ali_Nawaz 

To confirm you want to remove the duplicates from a SQL table containing only 20-30 records, correct?  Just wanted to make sure that is the full table size, not the number of records to delete.

 

This info is helpful because when we are under 500 records in the table we can ignore delegation rules.

 

There could be more than 500 records present in the table at the time of deletion. 
But the records which need to be deleted will be around 20-30. 


Hi @Ali_Nawaz ,

Do you want to remove multiple records from your SQL Table based on specific "Worker Number" , 'PayperiodStart" , 'PayperiodEnd" value?

 

Based on the needs that you mentioned, I think the RemoveIf function could achieve your needs. You could consider add a Text Input box (TextInput1) and two DatePicker controls (StartDatePicker & EndDatePicker) in your app.

 

I have made a test on my side, please consider take a try with the following workaround:

Set the OnSelect property of the "Remove" button:

RemoveIf(
         '[dbo].[YourSQLTable]',
         'Worker Number' = TextInput1.Text && Text(PayperiodStart, "yyyymmdd") = Text(StartDatePicker.SelectedDate, "yyyymmdd") && Text(PayperiodEnd, "yyyymmdd") = Text(EndDatePicker.SelectedDate, "yyyymmdd")
)

 

In addition, as an alternative solution, you could also consider add a Gallery within your app to list all avaiable records from your SQL Table. Then add a Checkbox control (Checkbox1) within the Gallery. If you want to remove the specific item, please check the corresponding Checkbox within the Gallery for specific item.

Outside, the Gallery, add a "Remove" button, set the OnSelect property to following:

ForAll(
       RenameColumns(Filter(Gallery1.AllItems, Checkbox1.Value = true), "ID", "ID1"),
       Remove('[dbo].[YourSQLTable]', LookUp('[dbo].[YourSQLTable]', ID = ID1))
)

Note:  I assume that the "ID" is a Primary Key column in your SQL Table.

 

Best regards,

Community Support Team _ Kris Dai
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

Helpful resources

Announcements
PA User Group

Welcome to the User Group Public Preview

Check out new user group experience and if you are a leader please create your group

secondImage

Demo Extravaganza Winner Announcement

Please join us on Wednesday, July 21st at 8a PDT. We will be announcing the Winners of the Demo Extravaganza!

V3_PVA CAmpaign Carousel.png

Community Challenge - Giveaways!

Participate in the Power Virtual Agents Community Challenge

Carousel 2021 Release Wave 2 Plan 768x460.jpg

2021 Release Wave 2 Plan

Power Platform release plan for the 2021 release wave 2 describes all new features releasing from October 2021 through March 2022.

Top Solution Authors
Top Kudoed Authors
Users online (2,137)