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 Apps
Answered

Toggle Values

(0) ShareShare
ReportReport
Posted on by 122
I have three buttons that I was able to set to toggle and change color so that when they are true, they = Red and when they are false, they = Blue. On Select: UpdateContext({ButtonOne:!ButtonOne}), Fill: If(ButtonOne=true, Color.Red, Color.Blue) Pretty simple. However, I need to essentially keep score and set variables for each button when true and false. If Button One = true, Red = 1 and Blue = 0. If ButtonOne = false, Blue = 1 and Red =0. They are either 1 or 0, that's it. Therefore, if two buttons are red and one is blue, red wins 2-1. This seems so simple but I can't figure it out. Any assistance would be appreciated.
Categories:
I have the same question (0)
  • Andy_Tuke Profile Picture
    141 on at

    First things first, in any test of boolean values you dont need to say

    Fill: If(ButtonOne=true, Color.Red, Color.Blue)

    you can simply say

    Fill: If(ButtonOne, Color.Red, Color.Blue)

    as ButtonOne=true will return true if it is true, in which case just use its true value.

     

    If you are only going to have 3 toggles, each of which are either True or False you can then use

     

    If ((ButtonOne && ButtonTwo) OR (ButtonOne && ButtonThree) OR (ButtonTwo && ButtonThree), <actioniftrue>,<actioniffalse>)

    The If statement will evaluate to True if any 2 of the buttons are enable, ie true.  If you start adding more buttons the If statement will start getting longer exponentially.  In which case you would probably want to keep a 'Total' variable and increment/decrement it as the buttons are toggled.

     

    Andy
    Read my new blog at -
    www.powerappssolution.com

  • dinusc Profile Picture
    Microsoft Employee on at

    You should be able to count all the states separately if you modify your "OnSelect" formula as following:

    UpdateContext({ButtonOne:!ButtonOne});UpdateContext({t:t+If(ButtonOne,1,0)}); UpdateContext({f:f+If(ButtonOne,0,1)})

    Here, "t" has the counts of all the "true" states and "f" - all the counts of "false" states. 

  • Verified answer
    hughrmarks Profile Picture
    122 on at
    Thank you for your reply. The problem is that with your formula, the values of each successively increase by one each time I select. So if I click five times, the value of red (true) will be 3 and the value of blue (false) will be 2. I need to have it so that successive clicks make it either 1-0 for red or 1-0 for blue. First click makes it 1-0 red, next click makes it 1-0 blue, next click makes it 1-0 red, next click makes it 1-0 blue, etc.
  • hughrmarks Profile Picture
    122 on at
    Thanks Andy, I changed all of my IF statements to shorten the formulas. I used bits and pieces from multiple answers to fix the problem.

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
WarrenBelz Profile Picture

WarrenBelz 519 Most Valuable Professional

#2
11manish Profile Picture

11manish 489

#3
Haque Profile Picture

Haque 327

Last 30 days Overall leaderboard