cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
pedromoreno
Regular Visitor

IF and ELSE Function to rotate true and false

Hi,

 

Lets say i have got a button that every time it does thefollowing:

If A is enabled, disbale A and Enable B and If B is enabled, disbale B and Enable A

 

This is what i have in Button Action:

If(EnabledA;true) - UpdateContext({EnabledA: false}) & UpdateContext({EnabledB: true}) - (false) - UpdateContext({EnabledA: true}) & UpdateContext({EnabledB: false})

 

It seems just to do the last part: A Ends up enabled

If i remove the part in front of "-"  B stays enabled

 

I'm doing somethng wroug but i cant find the way to aply else or else if... something ike that...

 

Thank you in advance

 

 

1 ACCEPTED SOLUTION

Accepted Solutions

I think I understand :). You can update multiple variables in the same UpdateContext call, and if you use the If function, you can perform an action in the case of the condition being true and another one in the case the condition is false. I think this should do what you need:

If(
    EnabledA;
    UpdateContext({EnabledA: false; EnabledB: true};
    UpdateContext({EnabledA: true; EnabledB: false})
)

View solution in original post

3 REPLIES 3
CarlosFigueira
Power Apps
Power Apps

You can use a single variable, and use the Not function (or the ! operator), to have opposite values for it. Here is one way you can implement that:

ButtonA.Disabled: !EnabledA
ButtonA.OnSelect: UpdateContext({ EnabledA: !EnabledA })

ButtonB.Disabled: EnabledA
ButtonB.OnSelect: UpdateContext({ EnabledA: !EnabledA })

When any button is clicked, the value of the EnabledA variable is toggled between true and false.

 

Hope this helps!

I only have one button, and i want that button to control the 2 variables becouse they are used for other stuff also.

What you have just showed me should work very fine for other stuff that i can make simple.. thank you 🙂

 

But i need to control that one with the IF statment.. any ideas 🙂

I think I understand :). You can update multiple variables in the same UpdateContext call, and if you use the If function, you can perform an action in the case of the condition being true and another one in the case the condition is false. I think this should do what you need:

If(
    EnabledA;
    UpdateContext({EnabledA: false; EnabledB: true};
    UpdateContext({EnabledA: true; EnabledB: false})
)

View solution in original post

Helpful resources

Announcements
PA_User Group Leader_768x460.jpg

Manage your user group events

Check out the News & Announcements to learn more.

Power Query PA Forum 768x460.png

Check it out!

Did you know that you can visit the Power Query Forum in Power BI and now Power Apps

Carousel 2021 Release Wave 2 Plan 768x460.jpg

2021 Release Wave 2 Plan

Power Platform release plan for the 2021 release wave 2 describes all new features releasing from October 2021 through March 2022.

R2 (Green) 768 x 460px.png

Microsoft Dynamics 365 & Power Platform User Professionals

DynamicsCon is a FREE, 4 half-day virtual learning experience for 11,000+ Microsoft Business Application users and professionals.

Users online (1,355)