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

Counting how many yes in a radio button.

Hi ,

I have a app I am building. In this app it ask's about 15 questions with radio buttons that have a yes or no answer. I need to write a if statement  that counts how many yes's there are and if it more than 2 it changes the screen color.  With the help from user @mdevaney  I implemented the following code. 

 

If((If(Radio1_26.SelectedText.OptionText ="No",2,0)+If(Radio1_2.SelectedText.OptionText ="Yes",1,0)+If(Radio1_3.SelectedText.OptionText ="Yes",1,0)+If(Radio1_4.SelectedText.OptionText ="Yes",1,0)+If(Radio1_5.SelectedText.OptionText ="Yes",1,0)+If(Radio1_6.SelectedText.OptionText ="Yes",1,0)+If(Radio1_7.SelectedText.OptionText ="Yes",1,0)+If(Radio1_8.SelectedText.OptionText ="Yes",1,0)+If(Radio1_9.SelectedText.OptionText ="Yes",1,0)+If(Radio1_10.SelectedText.OptionText ="Yes",1,0)+If(Radio1_14.SelectedText.OptionText ="Yes",1,0)+If(Radio1_15.SelectedText.OptionText ="Yes",1,0)+If(Radio1_16.SelectedText.OptionText ="Yes",1,0))>1,Green,Red)

 

 

Un fortunately no mater how many yes's or no's are selected it always stays green. I'm not sure what i have done wrong. any help would be greatly appreciated. 

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
Super User III
Super User III

Re: Counting how many yes in a radio button.

@dshawSLDC 

You might consider the following formula as a replacement:

If(    
    CountRows(
        Filter(
            Split(
                Radio1_26.Selected.OptionText & ";" &
                Radio1_2.Selected.OptionText & ";" &
                Radio1_3.Selected.OptionText & ";" &
                Radio1_4.Selected.OptionText & ";" &
                Radio1_5.Selected.OptionText & ";" &
                Radio1_6.Selected.OptionText & ";" &
                Radio1_7.Selected.OptionText & ";" &
                Radio1_8.Selected.OptionText & ";" &
                Radio1_9.Selected.OptionText & ";" &
                Radio1_10.Selected.OptionText & ";" &
                Radio1_14.Selected.OptionText & ";" &
                Radio1_15.Selected.OptionText & ";" &
                Radio1_16.Selected.OptionText,
             ";"    
             ),
             Result="Yes"
         )
     ) > 1, Green,
     Red
)

 

I noticed that you had what appeared to be the opposite logic on the Radio1_26 control.  Not sure the significance of that.

But, if you want to count the Yes's, the above formula should do it.

If you need a weighted system of counting then I like @mdevaney's formula for the assignment of numeric values.

I also assume that your Radio control Items property has an "OptionText" field in it.

Avoid using the SelectedText property of the controls that have them as they have been deprecated. 

 

I hope this is helpful for you.

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up. Solved your problem? - Click on Accept as Solution. Others seeking the same answers will be happy you did.

View solution in original post

2 REPLIES 2
Highlighted
Super User III
Super User III

Re: Counting how many yes in a radio button.

@dshawSLDC 

You might consider the following formula as a replacement:

If(    
    CountRows(
        Filter(
            Split(
                Radio1_26.Selected.OptionText & ";" &
                Radio1_2.Selected.OptionText & ";" &
                Radio1_3.Selected.OptionText & ";" &
                Radio1_4.Selected.OptionText & ";" &
                Radio1_5.Selected.OptionText & ";" &
                Radio1_6.Selected.OptionText & ";" &
                Radio1_7.Selected.OptionText & ";" &
                Radio1_8.Selected.OptionText & ";" &
                Radio1_9.Selected.OptionText & ";" &
                Radio1_10.Selected.OptionText & ";" &
                Radio1_14.Selected.OptionText & ";" &
                Radio1_15.Selected.OptionText & ";" &
                Radio1_16.Selected.OptionText,
             ";"    
             ),
             Result="Yes"
         )
     ) > 1, Green,
     Red
)

 

I noticed that you had what appeared to be the opposite logic on the Radio1_26 control.  Not sure the significance of that.

But, if you want to count the Yes's, the above formula should do it.

If you need a weighted system of counting then I like @mdevaney's formula for the assignment of numeric values.

I also assume that your Radio control Items property has an "OptionText" field in it.

Avoid using the SelectedText property of the controls that have them as they have been deprecated. 

 

I hope this is helpful for you.

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up. Solved your problem? - Click on Accept as Solution. Others seeking the same answers will be happy you did.

View solution in original post

Highlighted
Regular Visitor

Re: Counting how many yes in a radio button.

Thanks, once I changed to selected instead of selectedtext it worked.

Helpful resources

Announcements
Community Conference

Power Platform Community Conference

Check out the on demand sessions that are available now!

Watch Now

Experience what’s next for Power Apps

See the latest Power Apps innovations, updates, and demos from the Microsoft Business Applications Launch Event.

Power Platform ISV Studio

Power Platform ISV Studio

ISV Studio is designed to become the go-to Power Platform destination for ISV’s to monitor & manage published applications.

secondImage

Power Platform 2020 release wave 2 plan

Features releasing from October 2020 through March 2021

Top Solution Authors
Top Kudoed Authors
Users online (7,094)