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

Set Variable

(0) ShareShare
ReportReport
Posted on by 27

Dear All,

 

I have some selected questions and would like to set variables for them, for example, "VarDisQuestions".

So when the Question Number is not one of them, then the other field "Question" will be Visible. 

This works fine when the question number is one of them (for example, when question number is 16, "Question" is visible;

but when the question number is 2, "Question" is still visible. Would you please help? thank you. 

 

This is my code:

Set Variable Main Screen, OnVisible

 

Set(VarDisQuestion,(QuestionNumberLabel.Selected.'Question Number' = 1 ||

    QuestionNumberLabel.Selected.'Question Number' = 2 ||

    QuestionNumberLabel.Selected.'Question Number' = 3 ||

    QuestionNumberLabel.Selected.'Question Number' = 4 ||

    QuestionNumberLabel.Selected.'Question Number' = 5 ||

    QuestionNumberLabel.Selected.'Question Number' = 6 ||

    QuestionNumberLabel.Selected.'Question Number' = 10 ||

    QuestionNumberLabel.Selected.'Question Number' = 11 ||

    QuestionNumberLabel.Selected.'Question Number' = 13 ||

    QuestionNumberLabel.Selected.'Question Number' = 14 ||

    QuestionNumberLabel.Selected.'Question Number' = 15 ||

)

 

Question, Visible

If(
   !VarDisQuestion,
    true,
    false
)
Categories:
I have the same question (0)
  • ypatil2 Profile Picture
    on at

    @Quincy_Chan  What is QuestionNumberLabel.Selected.'Question Number', is it dropdown. If yes then where you are using it.  

  • Verified answer
    Uismayil Profile Picture
    55 on at

    Hi @Quincy_Chan 

     

    You may try below code:

     

    Set(
    VarDisQuestion,
    Not(
    QuestionNumberLabel.Selected.'Question Number' = 1 ||
    QuestionNumberLabel.Selected.'Question Number' = 2 ||
    QuestionNumberLabel.Selected.'Question Number' = 3 ||
    QuestionNumberLabel.Selected.'Question Number' = 4 ||
    QuestionNumberLabel.Selected.'Question Number' = 5 ||
    QuestionNumberLabel.Selected.'Question Number' = 6 ||
    QuestionNumberLabel.Selected.'Question Number' = 10 ||
    QuestionNumberLabel.Selected.'Question Number' = 11 ||
    QuestionNumberLabel.Selected.'Question Number' = 13 ||
    QuestionNumberLabel.Selected.'Question Number' = 14 ||
    QuestionNumberLabel.Selected.'Question Number' = 15
    )
    )

     

    the Set function sets VarDisQuestion to true if the selected question number is NOT one of the specified numbers (1, 2, 3, ..., 15).

     

    to make the "Question" field visible only if VarDisQuestion is true, you may apply below code, which makes it visible when the selected question number is not one of the specified numbers.

     

    Question.Visible = VarDisQuestion

     

    PS: PowerApps variable scope is recommended to as less as possible, so try to use local variable(update context) or onetime variable (with function)

     

    If my response has helped resolve your issue, please consider clicking "Accept as Solution" and giving it a thumbs up so others can find it helpful. ….UIsmayil

  • Quincy_Chan Profile Picture
    27 on at

    Hi Uismayil, thanks a lot for your reply. The variable seems created successfully. However, it is not working in making the Question Visible. I don't think this is due to the selection of question number, because I can make it visible when I do it like this:

    Question.Visible=

    If(
        "Softlines" in ProductLineCombo.SelectedItems.Value &&
        Not(QuestionNumberLabel.Selected.'Question Number' = 1 ||
        QuestionNumberLabel.Selected.'Question Number' = 2 ||
        QuestionNumberLabel.Selected.'Question Number' = 3 ||
        QuestionNumberLabel.Selected.'Question Number' = 4 ||
        QuestionNumberLabel.Selected.'Question Number' = 5 ||
        QuestionNumberLabel.Selected.'Question Number' = 6 ||
        QuestionNumberLabel.Selected.'Question Number' = 10 ||
        QuestionNumberLabel.Selected.'Question Number' = 11 ||
        QuestionNumberLabel.Selected.'Question Number' = 13 ||
        QuestionNumberLabel.Selected.'Question Number' = 14 ||
        QuestionNumberLabel.Selected.'Question Number' = 15 ||
       ,
        true,
        false
    )
     
    I know this is really stupid to list out all the numbers, because this is not the only field I want to make it visible in this situation. 😞 Hopefully you can help me.
     
    Update: 
    I added a column "Visible" to the Question Database and when the specific question should be visible, then the value of Visible will be "Y".
    Not sure is it the best way to do so, but works fine and clear now. Thanks a lot for all of your help!
     
    Question.Visible = If("Softlines" in ProductLineCombo.SelectedItems.Value And
    VisibleDropdown.Selected.Visible="Y"
    ,true,false)

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
11manish Profile Picture

11manish 530

#2
WarrenBelz Profile Picture

WarrenBelz 459 Most Valuable Professional

#3
Haque Profile Picture

Haque 314

Last 30 days Overall leaderboard