web
You’re offline. This is a read only version of the page.
close
Skip to main content
Community site session details

Community site session details

Session Id : z5IdS8TbEZabzqKIMcCL8z
Power Apps - Building Power Apps
Answered

If condition inside foreach loop for collection not working

Like (0) ShareShare
ReportReport
Posted on 19 Mar 2024 09:20:33 by 112

I have 2 collections as shown in below images.

shrikantswnt_0-1710839743287.png

shrikantswnt_1-1710839794574.png

 

I have applied Foreach loop, inside which I am checking If Condition which is not working. Code is as below


ForAll(
collAdditionalPassenger,
If(CountRows(Filter(collVMSFuture,Title = CPR))=0,
Patch(
'Visitor Details',
Defaults('Visitor Details'),
{ CPR: CPR,
Name:Name,
Organization:Organization,
Mobile: Mobile,
CarPassRequired: If(Lower(CarPass)="false", false, true),
CarID:CarID
}
)
)
);

 

 

  • Suggested answer
    shrikantswnt Profile Picture
    112 on 16 Feb 2025 at 07:17:00
    If condition inside foreach loop for collection not working
    @BhaskarDhone : Its working. its all because of column name.
  • shrikantswnt Profile Picture
    112 on 19 Mar 2024 at 11:50:49
    Re: If condition inside foreach loop for collection not working

    Thanks for the reply @BhaskarDhone .

    But the behaviour is the same even after changing the code.

    If I manually check for value it works fine For ex.
    If(CountRows(Filter(collVMSFuture,Title = "777777773"))=0,

     

    but if I use runtime value it is skipping the condition 
    If(CountRows(Filter(collVMSFuture,Title = collAdditionalPassengerA.CPR))=0,

     

     

     

     

  • Verified answer
    BhaskarDhone Profile Picture
    1,129 Super User 2025 Season 2 on 19 Mar 2024 at 10:33:55
    Re: If condition inside foreach loop for collection not working

    May be because of same column name system is getting confused

    Try this

    ForAll(
    collAdditionalPassenger As PassengerCollection,
    If(CountRows(Filter(collVMSFuture,Title = PassengerCollection.CPR))=0,
    Patch(
    'Visitor Details',
    Defaults('Visitor Details'),
    { CPR: PassengerCollection.CPR,
    Name:PassengerCollection.Name,
    Organization:PassengerCollection.Organization,
    Mobile: PassengerCollection.Mobile,
    CarPassRequired: If(Lower(PassengerCollection.CarPass)="false", false, true),
    CarID:PassengerCollection.CarID
    }
    )
    )
    );

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Announcing our 2025 Season 2 Super Users!

A new season of Super Users has arrived, and we are so grateful for…

Paul Stork – Community Spotlight

We are honored to recognize Paul Stork as our July 2025 Community…

Congratulations to the June Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 791 Most Valuable Professional

#2
MS.Ragavendar Profile Picture

MS.Ragavendar 410 Super User 2025 Season 2

#3
mmbr1606 Profile Picture

mmbr1606 275 Super User 2025 Season 2

Loading complete