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 Platform Community / Forums / Power Apps / Combobox update a numb...
Power Apps
Suggested Answer

Combobox update a number variable depending on Yes or No selection

(1) ShareShare
ReportReport
Posted on by 86
Hi,
 
Please can anyone suggest a solution - i am using a Canvas App.
 
I have a Number Variable :
varBinCalcCheck that is a Global Variable that is set at 0 at App startup.
 
I have four Comboboxes that are "Yes" or "No" selkections.
 
cmbQuestionOne
cmbQuestionTwo
cmbQuestionThree
cmbQuestionFour
 
If ,
 
cmbQuestionOne.Selected ="Yes" or cmbQuestionOne.Selected = "No" then i want to add 1 to varBinCalcCheck (varBinCalcCheck = varBinCalcCheck +1)
cmbQuestionTwo.Selected ="Yes" or cmbQuestionTwo.Selected = "No" then i want to add 2 to varBinCalcCheck (varBinCalcCheck = varBinCalcCheck +2)
cmbQuestionThree.Selected ="Yes" or cmbQuestionThree.Selected = "No" then i want to add 4 to varBinCalcCheck (varBinCalcCheck = varBinCalcCheck +4)
cmbQuestionFour.Selected ="Yes" or cmbQuestionFour.Selected = "No" then i want to add 8 to varBinCalcCheck (varBinCalcCheck = varBinCalcCheck +8)
cmbQuestionFiveSelected ="Yes" or cmbQuestionFiveSelected = "No" then i want to add 16 to varBinCalcCheck (varBinCalcCheck = varBinCalcCheck +16)
 
So if all comboboxes were selected as "Yes" then varBinCalcCheck = 31 (also if varBinCalcCheck = 31 then send a simple notification saying "All comboboxes have been answered".)
 
and if for example,
 
(if cmbQuestionThree.Selected was not selected as "Yes" or "No" then varBinCalcCheck = 27
 
If any combobox.Selected is not equal to "Yes" or "No" (so not selected then i would add 0 to varBinCalcCheck
 
Would this be best put in the "On Change" event?
 
Assuming i would need to add the whole code for each combobox "On Change" event, rather than individually.
But maybe a better solution for just the fx for the combobox itself on each.
 
So the code for
 
cmbQuestionOne fx would only be in the "On Change" event for comboboxOne
cmbQuestionTwo fx would only be in the "On Change" event for comboboxTwo
cmbQuestionThree fx would only be in the "On Change" event for comboboxThree
cmbQuestionFour fx would only be in the "On Change" event for comboboxFour
cmbQuestionFive fx would only be in the "On Change" event for comboboxFive
 
Any advice greatly appreciated.
I have the same question (0)
  • Suggested answer
    Dhanush Pamarthi Profile Picture
    8 on at
    Hi,
     
    For this scenario, I would not recommend adding 1, 2, 4, 8, 16 incrementally in each ComboBox OnChange, because the value can easily become incorrect if the user changes an answer more than once.
     
    For example, if the user selects Question 1, then changes it again, the variable could be incremented again and give the wrong total.
     
    The better approach is to recalculate the full value every time any ComboBox changes.
     
    Assuming each ComboBox only allows one selected value and the selected value is either "Yes" or "No", you can use this formula.
     
    Set the same formula in the OnChange property of each ComboBox:
     
    With(
        {
            calcValue:
                If(!IsBlank(cmbQuestionOne.Selected.Value), 1, 0) +
                If(!IsBlank(cmbQuestionTwo.Selected.Value), 2, 0) +
                If(!IsBlank(cmbQuestionThree.Selected.Value), 4, 0) +
                If(!IsBlank(cmbQuestionFour.Selected.Value), 8, 0) +
                If(!IsBlank(cmbQuestionFive.Selected.Value), 16, 0)
        },
        Set(varBinCalcCheck, calcValue);
     
        If(
            calcValue = 31,
            Notify(
                "All comboboxes have been answered",
                NotificationType.Success
            )
        )
    )
    This works because:
     
    • Question 1 answered = add 1
    • Question 2 answered = add 2
    • Question 3 answered = add 4
    • Question 4 answered = add 8
    • Question 5 answered = add 16
    If all five are answered:
    1 + 2 + 4 + 8 + 16 = 31
    So varBinCalcCheck = 31 means all ComboBoxes have a value selected.
     
     
    If this helped solve your issue, please Accept as Solution so others can find it quickly.

     If it didn’t fully solve it but was still useful, please click “Yes” on “Was this reply helpful?” or leave a Like :).

     
  • Suggested answer
    Valantis Profile Picture
    6,488 on at
     
    Dhanush's approach is exactly right. Recalculating the full value on every OnChange is the correct pattern, never increment/decrement, it breaks on multiple selections.
     
    One addition: instead of placing the same formula in all 5 OnChange properties (which means maintaining it in 5 places), use a named formula or put the calculation in a single reusable expression. The cleanest way in Power Apps is to make varBinCalcCheck a computed label Text property instead of a variable, calculating it directly:
    If(!IsBlank(cmbQuestionOne.Selected.Value), 1, 0) +
    If(!IsBlank(cmbQuestionTwo.Selected.Value), 2, 0) +
    If(!IsBlank(cmbQuestionThree.Selected.Value), 4, 0) +
    If(!IsBlank(cmbQuestionFour.Selected.Value), 8, 0) +
    If(!IsBlank(cmbQuestionFive.Selected.Value), 16, 0)
     
    This auto-updates whenever any combobox changes, no OnChange code needed at all. Then on your submit button, check if that label's value equals 31 before proceeding. Simpler and no OnChange maintenance.
     

     

    Best regards,

    Valantis

     

    ✅ If this helped solve your issue, please Accept as Solution so others can find it quickly.

    ❤️ If it didn’t fully solve it but was still useful, please click “Yes” on “Was this reply helpful?” or leave a Like :).

    🏷️ For follow-ups  @Valantis.

    📝 https://valantisond365.com/

    💼 LinkedIn

    ▶️ YouTube

  • Suggested answer
    11manish Profile Picture
    3,029 on at
    You can use the OnChange event, but rather than incrementing varBinCalcCheck each time a user makes a selection, it's better to recalculate the
     
    total based on the current state of all comboboxes. This avoids issues when users change their answers multiple times.

    Set the following formula in the OnChange property of each combobox:
    Set(
        varBinCalcCheck,
        If(!IsBlank(cmbQuestionOne.Selected), 1, 0) +
        If(!IsBlank(cmbQuestionTwo.Selected), 2, 0) +
        If(!IsBlank(cmbQuestionThree.Selected), 4, 0) +
        If(!IsBlank(cmbQuestionFour.Selected), 8, 0) +
        If(!IsBlank(cmbQuestionFive.Selected), 16, 0)
    );
    
    If(
        varBinCalcCheck = 31,
        Notify(
            "All comboboxes have been answered",
            NotificationType.Success
        )
    )
     

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

Season of Sharing Community Challenge Launch!

Jump in, show your community spirit, and win prizes!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Congratulations to the May Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Apps

#1
Valantis Profile Picture

Valantis 471

#2
WarrenBelz Profile Picture

WarrenBelz 395 Most Valuable Professional

#3
11manish Profile Picture

11manish 279

Last 30 days Overall leaderboard