cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
Helper V
Helper V

How can I use ForAll and RemoveIf to remove items in one collection that are missing in another?

I have two collections I want to compare so I can ensure they match exactly. Here are samples of the two collections:

Collection1

IDItem
3C

 

Collection2

IDItem
1A
2B
3C


How can I write my ForAll( RemoveIf ) so it removes IDs 1 and 2 from Collection2 because they are missing from Collection1?

2 REPLIES 2
Highlighted

Re: How can I use ForAll and RemoveIf to remove items in one collection that are missing in another?

Hi @pwrappr01 ,

 

I dont't think you need the ForAll in this case. The RemoveIf already allows you to loop through a table.

 

Why not do?: 

RemoveIf(Collection2, Not(ID in Collection1.ID))

 

Highlighted
Resolver IV
Resolver IV

Re: How can I use ForAll and RemoveIf to remove items in one collection that are missing in another?

Hi @pwrappr01 !

 

You dont need to use ForAll since RemoveIf loops through all lines anyway. Try this formula:

RemoveIf(
    Collection2,
    CountRows(
        Filter(
            Collection1,
            Id = Collection2[@Id] && Item = Collection2[@Item]
        )
    ) < 1
)

BR

Pontus

Helpful resources

Announcements
Community Conference

Power Platform Community Conference

Check out the on demand sessions that are available now!

Watch Now

Experience what’s next for Power Apps

See the latest Power Apps innovations, updates, and demos from the Microsoft Business Applications Launch Event.

Power Platform ISV Studio

Power Platform ISV Studio

ISV Studio is designed to become the go-to Power Platform destination for ISV’s to monitor & manage published applications.

secondImage

Power Platform 2020 release wave 2 plan

Features releasing from October 2020 through March 2021

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