cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
Ali_Nawaz
Level: Powered On

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
Community Support Team
Community Support Team

Re: Delete Multiple records in SQL from powerapps

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

Re: Delete Multiple records in SQL from powerapps

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

Ali_Nawaz
Level: Powered On

Re: Delete Multiple records in SQL from powerapps

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. 

Super User
Super User

Re: Delete Multiple records in SQL from powerapps

@Ali_Nawaz 

How many records in that SQL table of yours?

Ali_Nawaz
Level: Powered On

Re: Delete Multiple records in SQL from powerapps

There could be 20-30 records at once

Super User
Super User

Re: Delete Multiple records in SQL from powerapps

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

 

Ali_Nawaz
Level: Powered On

Re: Delete Multiple records in SQL from powerapps

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. 


Community Support Team
Community Support Team

Re: Delete Multiple records in SQL from powerapps

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
thirdimage

Power Apps Super User Class of 2020

Check it out!

thirdimage

New Badges

Check it out!

thirdimage

Power Apps Community User Group Member Badge

Fill out a quick form to claim your user group badge now!

sixthImage

Power Platform World Tour

Find out where you can attend!

Power Platform 2019 release wave 2 plan

Power Platform 2019 release wave 2 plan

Features releasing from October 2019 through March 2020

SecondImage

Difinity Conference

The largest Power BI, Power Platform, and Data conference in New Zealand

Top Solution Authors
Top Kudoed Authors
Users online (5,526)