cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
thatakke
Helper II
Helper II

Multiple If statements best practice

Hello,

 

I'm very new to PowerApps and I'm really struggling with the If statements. I want to ensure that the users answer all of the mandatory questions before navigating to the next screen. My current OnSelect function on the next button is:

 

If(IsEmpty(DataCardValue42.SelectedItems),
    If(IsEmpty(DataCardValue44.SelectedItems),
    If(IsEmpty(DataCardValue43.SelectedDate),
    Notify("You need to answer all mandatory questions",NotificationType.Error),Navigate(SignUp_Work,ScreenTransition.Cover))))

 

For some reason, it doesn't work, and I really don't understand how to write the best multiple If statements. Can anyone guide me?

 

Thanks,

 

1 ACCEPTED SOLUTION

Accepted Solutions
Eelman
Super User
Super User

@thatakke 

Seems like you could just use Or, ie

 

If(
IsEmpty(DataCardValue42.SelectedItems) ||
    IsEmpty(DataCardValue44.SelectedItems) ||
    IsEmpty(DataCardValue43.SelectedDate),
    Notify("You need to answer all mandatory questions",NotificationType.Error),Navigate(SignUp_Work,ScreenTransition.Cover))

View solution in original post

7 REPLIES 7
zmansuri
Super User
Super User

If(IsEmpty(DataCardValue42.SelectedItems),
If(IsEmpty(DataCardValue44.SelectedItems),
If(IsBlank(DataCardValue43.SelectedDate),
Notify("You need to answer all mandatory questions",NotificationType.Error),Navigate(SignUp_Work,ScreenTransition.Cover))))

 

Can you try this?

Eelman
Super User
Super User

@thatakke 

Seems like you could just use Or, ie

 

If(
IsEmpty(DataCardValue42.SelectedItems) ||
    IsEmpty(DataCardValue44.SelectedItems) ||
    IsEmpty(DataCardValue43.SelectedDate),
    Notify("You need to answer all mandatory questions",NotificationType.Error),Navigate(SignUp_Work,ScreenTransition.Cover))
Pstork1
Dual Super User
Dual Super User

The way I handle this is by using a counter.  Each time a required field is changed to a non-blank I increment the counter.  Each time a required field is changed to a blank value I decrement the counter.  then use a single If that checks to see if the counter is equal to or greater than the number of required fields on the screen to enable the submit button.



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

Many thanks @Eelman I see that it is very similar to Power BI actually. I don't understand why I failed.

This is a great idea! @Pstork1 I'm quite new to PowerApps as I mentioned (It's my 3rd week), can you guide me with that? Although I've received an answer to my question, it'd be nice to learn this method, as I've quite a lot of mandatory fields in another form. 

 

Thank you

Pstork1
Dual Super User
Dual Super User

For each required field put an IF() in the onChange event to increment a variable counter if the value is not blank or decrement the counter if it is blank.

 

Set the displayMode of the submit button to disabled if the counter is not equal to or greater than the number of required fields on the screen.



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

Thanks @Pstork1 It's a very smart approach. 

Helpful resources

Announcements
Power Platform Conf 2022 768x460.jpg

Join us for Microsoft Power Platform Conference

The first Microsoft-sponsored Power Platform Conference is coming in September. 100+ speakers, 150+ sessions, and what's new and next for Power Platform.

May UG Leader Call Carousel 768x460.png

June User Group Leader Call

Join us on June 28 for our monthly User Group leader call!

PA Virtual Workshop Carousel 768x460.png

Register for a Free Workshop

This training provides practical hands-on experience in creating Power Apps solutions in a full-day of instructor-led App creation workshop.

PA.JPG

New Release Planning Portal (Preview)

Check out our new release planning portal, an interactive way to plan and prepare for upcoming features in Power Platform.

Top Solution Authors
Users online (3,125)