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 get two If state...
Power Apps
Answered

Can't get two If statements to work in Default of DropDown

(0) ShareShare
ReportReport
Posted on by 134

Hi,

I can't get all the functions of my drop down to work as they should all at the same time. If I add them separately, they will work or I can get two functions to work, but then something else stops working.  Basically, I have two drop downs and a button. When the dropdown1 changes to "Option2", dropdown2 should change to "Option2". Also, when the button pressed, dropdown2 should change to "Option2".  Here is my code set in the Default property of dropdown 2:

If(dropdown1.Selected.Value = "Offboard Resource", "Off-Board", "On-Board") ||
If(button.Pressed = true, "Off-Board", "On-Board")

This formula isn't actually working right now. I have run through so many different ways of writing this that I can't remember what worked at this point. I also have this code in dropdown1's OnChange property, which doesn't seem to be doing anything either:

If(dropdown1.Selected.Value = "Offboard Resource", dropdown2.Selected.Value = "Off-Board", "On-Board")

For the button's OnSelect property, I have this:

If(button.Pressed = true, dropdown2.Selected.Value = "Off-Board", "On-Board")

 I have tried using &, &&, a comma, a semi-colon, getting rid of parenthesis and using a comma for the If statements in dropdown2's Default property and either one statement will work and the other won't or both will work, but won't change the option automatically back to "On-Board". I have gotten both to work ONLY when I don't add the else "On-board" in there. It doesn't make any sense to me why it is all working together, but it's not. If anyone can give me anything to try, I would be grateful. Let me know if you need any more information.

Categories:
I have the same question (0)
  • LS579 Profile Picture
    134 on at

    I figured out that I can get this formula to work... but the button only works if dropdown1 is not "Offboard Resource" and I can't get the other two options for dropdown1 to default to "On-Board" because it won't work if I put an else statement in there other than what is in there.

     

    If(dropdown1.Selected.Value = "Offboard Resource", "Off-Board", If(button.Pressed = true, "Off-Board")

     

    ...but not this:

     

    If(dropdown1.Selected.Value = "Offboard Resource", "Off-Board", If(button.Pressed = true, "Off-Board"), "On-Board")

     

    and not if I have an else "On-Board" anywhere in the formula

  • Verified answer
    madlad Profile Picture
    2,637 Moderator on at

    For what you're trying to do, I think you want to use a variable. 

     

    Try something like this:

     

    Screen's OnVisible:

     

    Set(drp2Default, false)

     

     

    dropdown1's OnChange:

     

    If(Self.Selected = "Offboard Resource", Set(drp2Default, true))

     

     

    Button's OnSelect:

     

    Set(drp2Default, true);

     

     

    And in dropdown 2 Default:

     

    If(drp2Default, "Off-Board", "On-Board")

     

     

    This uses a true/false variable, and if the dropdown 1 is changed to Off Board or the button is pressed, then the dropdown 2 will change it's default value to be "Off-Board". 

     

    Hope this helps!

  • LS579 Profile Picture
    134 on at

    That worked, partially. If I select another option in dropdown1, it still doesn't change back to "On-Board"

  • Verified answer
    madlad Profile Picture
    2,637 Moderator on at

    Ah I missed that you wanted it to change back if dropdown 1 changed. 

    Replace dropdown 1 OnChange with:

    If(Self.Selected = "Offboard Resource", Set(drp2Default, true), Set(drp2Default, false))

     

  • LS579 Profile Picture
    134 on at

    That works! Thank you so much! I don't work much with variables, so I never would have figured that out. Thanks again!

  • LS579 Profile Picture
    134 on at

    Hi,

    I am having an issue with my app again and I think it has something to do with the solution you gave me, so I wanted to ask you first. 

     

    When I first applied your solution, the app worked fine, but I had to go away from it for a little while and when I went back into it, it started malfunctioning. after I choose the drop down to change the onboard to offboard, a button and additional fields on the first page should pop up, but what is happening is when I switch to the other page, the off-board is switching itself to onboard and those options are going away. No idea why it would be doing this. If you have any ideas, that would be helpful. Thanks!

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Users!

Kudos to our 2025 Community Spotlight Honorees

Congratulations to our 2025 community superstars!

Congratulations to the March Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Apps

#1
11manish Profile Picture

11manish 541

#2
WarrenBelz Profile Picture

WarrenBelz 434 Most Valuable Professional

#3
Valantis Profile Picture

Valantis 289

Last 30 days Overall leaderboard