cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Anonymous
Not applicable

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 @Anonymous ,

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
Super User

@Anonymous 

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

Anonymous
Not applicable

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. 

@Anonymous 

How many records in that SQL table of yours?

Anonymous
Not applicable

There could be 20-30 records at once

@Anonymous 

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.

 

Anonymous
Not applicable

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 @Anonymous ,

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.

Helpful resources

Announcements
Ignite 2022

WHAT’S NEXT AT MICROSOFT IGNITE 2022

Explore the latest innovations, learn from product experts and partners, level up your skillset, and create connections from around the world.

Power Apps Africa Challenge 2022

Power Apps Africa Challenge

Your chance to join an engaging competition of Power Platform enthusiasts.

Top Kudoed Authors
Users online (4,087)