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

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / Using IF or Switch bas...
Power Apps
Answered

Using IF or Switch based on variable answer

(0) ShareShare
ReportReport
Posted on by

I have a Variable(varLevels) that could have 3 conditions     "1" or "2" or "3"

 

If  varLevels  =  1 , do this 

    varlevels  = 2  , do this

   varLevels =  3  , do this

 

else  , do this 

 

Just looking to see what is the most efficient

 

Thanks

Dave 

Categories:
I have the same question (0)
  • Community Power Platform Member Profile Picture
    on at

    Hi!

     

    For your use case I would say the Switch is the most efficient since you won't need to have If statements inside other If statements, and you can use a default action (refering to the else {do this}). 


    Making your code more organized,clear to understand and easier to change if necessary!

  • Verified answer
    RandyHayes Profile Picture
    76,297 Super User 2024 Season 1 on at

    @Anonymous 

    The general rule on one over the other is - Use switch if your comparison is one-to-one.  Use If if you have to compare based on a formula.

     

    For example, if you are comparing one-to-one, then Switch:

    Switch(someValue,
     "Specific Value 1", <functions>,
     "Specific Value 2", <functions>,
     <functions> // ELSE - when no condition above is met
    )

     

    Using If:

    If(someValue > 10, <functions>,
     someValue > 5, <functions>,
     someValue = 4, <functions>,
     <functions> // ELSE when no conditions above are met
    )

     

    I hope this is helpful for you.

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

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 739 Most Valuable Professional

#2
Michael E. Gernaey Profile Picture

Michael E. Gernaey 343 Super User 2025 Season 2

#3
Power Platform 1919 Profile Picture

Power Platform 1919 268

Last 30 days Overall leaderboard