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

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / Can't give multiple co...
Power Apps
Answered

Can't give multiple conditions to single sign in button

(0) ShareShare
ReportReport
Posted on by Microsoft Employee

I'm creating an app which has to check if the User() is in the database with his email. From that I need to check the role of this person (Trainee, Instructor or Admin).

Based on this the button needs to direct them to the right screen. If their email is not in the database, an error pops up saying they need to register.

 

My code is currently as follows: 

If(

    Text(TextInput1) in '[dbo].[vStudents]'.Email && LookUp('[dbo].[vEmployees]',Type= "Student",       Navigate(HomeScreen_Trainee,ScreenTransition.None)),

    If(

       Text(TextInput1) in '[dbo].[vTeacherCourses]'.Email && LookUp('[dbo].[vEmployees]',Type= "Teacher",                           Navigate(HomeScreen_Instructor,ScreenTransition.None)),false);

 

Who knows how to solve this?!

Categories:
I have the same question (0)
  • Verified answer
    chrisog Profile Picture
    213 on at

    Hi @Anonymous,

     

    A few smaller issues before I look at the formula as a whole:

     

    Looking at your existing code, the first thing to mention is the LookUp() function. The syntax for LookUp() is LookUp(DataSource, Condition, Result)

     

    This section:

    LookUp('[dbo].[vEmployees]',Type= "Student",

    Is missing a Result and needs to be closed with ) before moving on to the If-true statement.

     

    Secondly, there is a function, Switch(), which is great for replacing nested If statements. The syntax is Switch(switch_value,  match_value, match_result, ..., default_value). To explain this in real terms, you may have something like Switch(true, variable1 > 10, "Variable is greater than 10", variable > 5, "Variable is greater than 5", "Variable is not greater than 5")

    This is a rather simple example, but it shows how you can set an initial switch value, and then each of the match values compare to that switch value and return the match result if true. Bear in mind, the Switch function always returns the first result that matches. 

     

    Switch is easier to maintain than mulitple Ifs, and you can have as many conditions as you want.

     

    Now assuming I have this correct and the user types their name (or identifying text) into the TextInput1 and then presses a button to submit, I will try to provide 2 examples of solutions. Unfortunately, I do not quite understand the configuration of your data to solve the opened LookUp functions but I will try.

     

    If(

        Text(TextInput1) in '[dbo].[vStudents]'.Email && LookUp('[dbo].[vEmployees]',Text(TextInput1) in Email, Type) = "Student",       Navigate(HomeScreen_Trainee,ScreenTransition.None),

        If(

           Text(TextInput1) in '[dbo].[vTeacherCourses]'.Email && LookUp('[dbo].[vEmployees]',Text(TextInput1) in Email, Type)= "Teacher", Navigate(HomeScreen_Instructor,ScreenTransition.None),Notify("The employee entered is not in the database, NotificationType.Error));

     

     

    Switch(LookUp('[dbo].[vEmployees]',Text(TextInput1) in Email, Type), "Student",  Navigate(HomeScreen_Trainee, ScreenTransition.None),Notify("This student is not found in the database", NotificationType.Error)) , "Teacher", If(TextInput1.Text in '[dbo].[vTeacherCourses]'.Email,Navigate(HomeScreen_Instructor,ScreenTransition.None),Notify("The teacher entered is not in the database", NotificationType.Error)))

     

     

    I hope this makes sense. Feel free to message me you need more help or ask to clarify anything within my post.

  • Community Power Platform Member Profile Picture
    Microsoft Employee on at

    Hi @chrisog ,

     

    Thank you for your fast reply. 

     

    I've tried both solutions and can't seem to make it work. It says it misses the End of Fomula where the ";" is at the first solution. And the second one stops at the vStudent and does not look at the teacher.

     

    The vEmployees database is as follows:

    |Name|Email|Type|

    |............|...........|Student|

    |............|...........|Instructor|

    |............|...........|Admin|

    |............|...........|Student|

     

    The other are a subset of this.

     

    The real challange is to be able to link the email to the Type and then make the Type determine the behavior of the button.

     

    Attached is a Screenshot of the loginscreen. 

     

     

    LoginScreenPowerApp.png
  • Verified answer
    Community Power Platform Member Profile Picture
    Microsoft Employee on at

    @Anonymous you should be able to remove the second "If(" code snippet and @chrisog 1st solution will work (see pic), or add another ")" before the ";" .

    ifStatement.png

    Nested Ifs are difficult to write and maintain but the If function can handle a number of If/Else conditions (up to 10 I think?) inside the same If() command like this:

     

    If( if-this1, then-that1,   if-this2, then-that2,  if-this3, then-that3 ... , else-this ) link

     

    Once I found PowerApps could handle this functionality I use it all the time. Very easy to maintain and write, if you ask me.

  • Community Power Platform Member Profile Picture
    Microsoft Employee on at

    Good morning @Anonymous ,

     

    Removing the first "If(" did the trick!

     

    Thank you @chrisog for taking the time to help out a starting PowerApps Developer!

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

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Congratulations to the July Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 355 Most Valuable Professional

#2
11manish Profile Picture

11manish 209 Super User 2026 Season 2

#3
MS.Ragavendar Profile Picture

MS.Ragavendar 150 Super User 2026 Season 2

Last 30 days Overall leaderboard