Skip to main content
Community site session details

Community site session details

Session Id : xOq1QCx3c1IJH2HGIQwDVb
Power Apps - Building Power Apps
Answered

Patch based on condition

Like (0) ShareShare
ReportReport
Posted on 16 May 2020 15:17:42 by 69

Hi Community, can I improve the below code to bring it into one IF statement instead of 2? The 3rd patch should be done at the same time as the second if the condition is met

If(
 MentorGallery.Selected.'Current Registrations' >= 5,
 Patch(
 UAWaitingList,
 {
 Title: User().FullName,
 MenteeMail: User().Email,
 Mentor: MentorGallery.Selected.Title
 }
 ),
 Patch(
 UARegistrationList,
 {
 Title: User().FullName,
 MenteeMail: User().Email,
 Mentor: MentorGallery.Selected.Title
 }
 )
);
If(
 MentorGallery.Selected.'Current Registrations' >= 5,
 Patch(
 UAMentorList,
 First(
 Filter(
 UAMentorList,
 ID = MentorGallery.Selected.ID
 )
 ),
 {CurrentRegistrations: MentorGallery.Selected.'Current Registrations' + 1}
 )
)

 

Thanks

Categories:
  • Verified answer
    v-xida-msft Profile Picture
    on 18 May 2020 at 08:10:33
    Re: Patch based on condition

    Hi @MarkH1 ,

    Could you please share a bit more about your scenario?
    Do you want to merge the two If condition into single one?

     

    I have made a test on my side, please modify your formula as below:

    If(
     MentorGallery.Selected.'Current Registrations' >= 5,
     Concurrent(
     Patch(
     UAWaitingList,
     Defaults(UAWaitingList),
     {
     Title: User().FullName,
     MenteeMail: User().Email,
     Mentor: MentorGallery.Selected.Title
     }
     ),
     Patch(
     UAMentorList,
     LookUp(UAMentorList,ID = MentorGallery.Selected.ID),
     {
     CurrentRegistrations: MentorGallery.Selected.'Current Registrations' + 1
     }
     )
     ),
     Patch(
     UARegistrationList,
     Defaults(UARegistrationList)
     {
     Title: User().FullName,
     MenteeMail: User().Email,
     Mentor: MentorGallery.Selected.Title
     }
     )
    )

    Note: The Concurrent function could execute multiple formulas simultaneously, which would improve your app's performance.

     

    Best regards,

  • KrishnaV Profile Picture
    5,023 on 16 May 2020 at 21:26:21
    Re: Patch based on condition

    Hi @MarkH1 ,

     

    All you need to do is add that patch right next to the first path. I am 100% sure  you know the syntax for if in Power Appss is:
    if(<<condition>>,true,false)

     

    If(5 > 3,
     UpdateContext({varValue1: "Value1"});
     UpdateContext({varValue2: "Value2"});
     ,
     UpdateContext({varValue3: "Value3"}); 
    )

     

    if see in the above code block I am executing 2 statement if the condition is met. having said that how we can achieve your need is as below.

     

    If(
     MentorGallery.Selected.'Current Registrations' >= 5,
     Patch(
     UAWaitingList,
     {
     Title: User().FullName,
     MenteeMail: User().Email,
     Mentor: MentorGallery.Selected.Title
     }
     );
     Patch(
     UAMentorList,
     First(
     Filter(
     UAMentorList,
     ID = MentorGallery.Selected.ID
     )
     ),
     {CurrentRegistrations: MentorGallery.Selected.'Current Registrations' + 1}
     );,
     Patch(
     UARegistrationList,
     {
     Title: User().FullName,
     MenteeMail: User().Email,
     Mentor: MentorGallery.Selected.Title
     }
     )
    );

     

    Hope this helps.

     

    Regards,

    Krishna


    If this reply/solution helps Mark it as the solution and give a thumbs-up.

     

  • Drrickryp Profile Picture
    Super User 2024 Season 1 on 16 May 2020 at 19:49:21
    Re: Patch based on condition

    Hi @MarkH1 

    Would this work?

     

    Switch( 
     MentorGallery.Selected.'Current Registrations' >= 5, 
    	Patch(
     UAWaitingList, 
     Defaults(
     'Current Registrations'
     ),
     {
     Title: User().FullName,
     MenteeMail: User().Email,
     Mentor: MentorGallery.Selected.Title
     }
     ),
     Patch(
     UARegistrationList,
     Defaults(
     UARegistrationList
     ),
     {
     Title: User().FullName,
     MenteeMail: User().Email,
     Mentor: MentorGallery.Selected.Title
     }
     ),
     Patch(
     UAMentorList,
     Lookup(
     UAMentorList,
     ID = MentorGallery.Selected.ID
     ),
     {
     CurrentRegistrations: MentorGallery.Selected.'Current Registrations' + 1
     }
     )
     )

     

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