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

Using a Loop to delete records from a Local List

Here is the situation:

 

Let us consider Table_A (a table coming from Excel), containing several columns, the most important one being the column ID, this table contains several records.
Now, let us consider the local collection Collec_B, created at app launch and also containing the column ID and several records.

I am looking for a way to loop through Collec_B and delete any record that has a matching ID with any of the records in Table_A. 
I thought using ForAll would be a good start, but it seems using the Remove function inside isn't allowed. Also I can't do it "manually" since both these tables change regularily.

 

Thank you for reading

1 ACCEPTED SOLUTION

Accepted Solutions
RandyHayes
Super User III
Super User III

@Anonymous 

Another option to consider is just using the RemoveIf function. 

Try changing your formula to this:

   RemoveIf(Collec_B, ID in (Table_A.ID))

This will remove any records in Collec_B that have an ID equal to any ID in Table_A.

 

I hope that is helpful.

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up below. Solved your problem? - Click on Accept as Solution below. Others seeking the same answers will be happy you did.
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes

Really want to show your appreciation? Buy Me A Cup Of Coffee!

View solution in original post

5 REPLIES 5
Pstork1
Dual Super User III
Dual Super User III

Can you duplicate just the ID's in Collec_B to another table or collection?  Then do a ForAll on that collection and do a remove from Collec_B by looking up the ID in the temp table with the records in Collec_B when you find a matching record in Table A



-------------------------------------------------------------------------
If I have answered your question, please mark your post as Solved.
If you like my response, please give it a Thumbs Up.
Anonymous
Not applicable

This would be a work around. 
Could you also help me on the overall logic to actually look for any matching record ?

As of now I have this formula:

ForAll (Collec_B_Bis; 
     If (ID = LookUp(Table_A; ID=ID).ID);
          Remove (Collec_B; ID = LookUp (Table_A; ID = ID))
      )
)
RandyHayes
Super User III
Super User III

@Anonymous 

Another option to consider is just using the RemoveIf function. 

Try changing your formula to this:

   RemoveIf(Collec_B, ID in (Table_A.ID))

This will remove any records in Collec_B that have an ID equal to any ID in Table_A.

 

I hope that is helpful.

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up below. Solved your problem? - Click on Accept as Solution below. Others seeking the same answers will be happy you did.
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes

Really want to show your appreciation? Buy Me A Cup Of Coffee!

View solution in original post

Pstork1
Dual Super User III
Dual Super User III

I actually like @RandyHayes solution below better.  Give that one a try.



-------------------------------------------------------------------------
If I have answered your question, please mark your post as Solved.
If you like my response, please give it a Thumbs Up.
Anonymous
Not applicable

Oops, forgot to reply. It indeed worked. Much thanks to both you and @Pstork1 for helping me.

Helpful resources

Announcements
PA_User Group Leader_768x460.jpg

Manage your user group events

Check out the News & Announcements to learn more.

Power Query PA Forum 768x460.png

Check it out!

Did you know that you can visit the Power Query Forum in Power BI and now Power Apps

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.

PowerPlatform 768x460.png

Microsoft Learn

Check out our new Discover Your Career Path blog post series and get all the details.

Users online (2,071)