cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
pwrappr01
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
Rebetcha
MVP

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))

 

pontusofsweden
Resolver IV
Resolver IV

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
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 is Back!

We are excited to announce that Demo Extravaganza for 2021 has started!

MBAS on Demand

Microsoft Business Applications Summit sessions

On-demand access to all the great content presented by the product teams and community members! #MSBizAppsSummit #CommunityRocks

Power Apps June 2021

June Power Apps Community Call

Don't miss the call this month on June 16th - 8a PDT

Top Solution Authors
Top Kudoed Authors
Users online (29,694)