cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
hughrmarks
Helper IV
Helper IV

Adding variables

I have five labels and each is assigned a variable (vLabel1, vLabel2, vLabel3, vLabel4, and vLabel5) so that OnSelect, it toggles between true and false. I have it set so that the label is blue when the variable is false and red when it is true. All I need to do is to calculate the number of red labels versus the number of blue. I am just finding it hard to create an equation to count the number of labels that are true versus the number that are false. I need to be able to say Red = 2, Blue = 3, for example.
2 REPLIES 2
timl
Super User
Super User

Hi @hughrmarks

 

One way to do this is to add your variables to a table. In the example below, the Table function creates a table with 5 rows. The column name is 'Variable' and each row in the table corresponds to a vLabelX variable.

You can then call the CountIf function and specify a condition to return a row count.

The formula to return a count of red labels would look like this:

CountIf(
        Table({Variable:vLabel1},{Variable:vLabel2}, {Variable:vLabel3},{Variable:vLabel4},{Variable:vLabel5}),
        Variable=true
)


The formula to return a count of blue labels would look like this:

 

CountIf(
        Table({Variable:vLabel1},{Variable:vLabel2}, {Variable:vLabel3},{Variable:vLabel4},{Variable:vLabel5}),
        Variable=false
)
v-xida-msft
Community Support
Community Support

Hi @hughrmarks,

 

I agree with @timl's thought almost, I have made a test on my side and my app's configuration as below:19.JPGAdd a Label control within your screen, the Text property of it set to following formula:

"Red="&CountIf(
        Table({Variable:vLabel1},{Variable:vLabel2}, {Variable:vLabel3},{Variable:vLabel4},{Variable:vLabel5}),
        Variable=true
)&", Blue="&CountIf(
        Table({Variable:vLabel1},{Variable:vLabel2}, {Variable:vLabel3},{Variable:vLabel4},{Variable:vLabel5}),
        Variable=false
)

Best regards,

Kris

 

Community Support Team _ Kris Dai
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Helpful resources

Announcements
Power Platform Conf 2022 768x460.jpg

Join us for Microsoft Power Platform Conference

The first Microsoft-sponsored Power Platform Conference is coming in September. 100+ speakers, 150+ sessions, and what's new and next for Power Platform.

May UG Leader Call Carousel 768x460.png

June User Group Leader Call

Join us on June 28 for our monthly User Group leader call!

PA Virtual Workshop Carousel 768x460.png

Register for a Free Workshop

This training provides practical hands-on experience in creating Power Apps solutions in a full-day of instructor-led App creation workshop.

PA.JPG

New Release Planning Portal (Preview)

Check out our new release planning portal, an interactive way to plan and prepare for upcoming features in Power Platform.

Top Solution Authors
Users online (1,349)