Showing results for 
Search instead for 
Did you mean: 
Post Prodigy
Post Prodigy

Count when RadioButton is Selected

I want to have a counter that decreases by one whenever a radio button is selected in the gallery. Currently the one I have works, but it resets whenever the app is closed. My app brings in previous responses with a lookup. How can I get the counter to stay at what it was previously at? If I reopened the app and submitted 10 radio buttons last time it would still say 46. Also, instead of me saying their are 46 radio buttons is there a way it could countRows of blank radio buttons. In my onselect for my counter I have Set(varRadioButtonSelectedCounter, 46); In the onchange for the radiobutton I have Set(varRadioButtonSelectedCounter, varRadioButtonSelectedCounter - 1); The default of the radio button is If(var,"",
LookUp(GUATResponses, Title=vUserMail && GUATListID=ThisItem.ID, RadioValue) . The text label of the counter is varRadioButtonSelectedCounter
) .


@powerapps890  I'd recommend to go with a collection...then you can see what's going on better than with filtering on the data source.



I am not really sure what to do with that... Isn't there a way I can use countRows? to count how many were previously selected @TJO 

@powerapps890  If the previous user entries are overwritten/updated the date is not relevant anymore for this. Could you try with a simple CountIf(GUATResponses, Title = vUserMail)

Well I actually came up with a solution but I need help tweaking it. I have a text label that says this varRadioButtonSelectedCounter - CountRows(collSelOptions). In my onvisible I set it to whatever number there is and then I use collSelOptions which is ClearCollect(collPrevUserVoting,Filter(GUATResponses,'Created By'.Email = varUser.Email));
ForAll(collPrevUserVoting,Collect(collSelOptions,{selName:Title})); so it pulls it from GUATResponses and will still decrease when a new is selected. The issue is if someone chooses a radio button for an item and then they switch their response for that item. The counter will go down even though all they did was change the item. @TJO 

Set(varRadioButtonSelectedCounter, varRadioButtonSelectedCounter - 1) is also in the onchange which is why it keeps taking away from the counter, so how can I do it based on a new item and not just a different selection within the same item. @TJO 

The solution you provided works its just a little slow @TJO 

@powerapps890 I'm thinking of a quite cumbersome solution, but it might do the trick: 

How about you set a variable for each radio (yes, a bit cumbersome) in the OnVisible property of the screen in question, and store the current status in each variable. Assuming your radio can have 4 values (0/Blank?, 1, 2, 3), you could then test if there was a relevant change, e.g.: 


      IsBlank(varRadio1),        //varRadio1 has been set with screen OnVisible
      !(IsBlank(Radio1.Value))   //Check if an option has been selected with Radio OnChange
   Set(varRadioButtonSelectedCounter, varRadioButtonSelectedCounter - 1);
   Set(varRadio1, Radio1.Value)  //Adjusting the Counter and store new status in variable


your solution actually works well in the label I just said it to subtract from the amount of items! However I manually have to input the amount of items is there a way for powerapps to just count the total amount of radio buttons selected or unselected maybe something like CountIfs(Radio4) @TJO 

@powerapps890  Maybe I'm stupid right now...How about you submit each radio value to your connected table, even if it hasn't been selected at all (e.g. Set Radio Value to "Not selected"). And then retrieve the initial value from your connected table?

   Mail = User().Email, 
      Mail = User().Email,
      RadioValue <> "Not selected"



Regular Visitor

Try this one, you won't depend on set a variable:





Helpful resources

Power Apps News & Annoucements carousel

Power Apps News & Announcements

Keep up to date with current events and community announcements in the Power Apps community.

Power Apps Community Blog Carousel

Power Apps Community Blog

Check out the latest Community Blog from the community!

Top Solution Authors
Top Kudoed Authors
Users online (3,896)