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 / Gallery show or hide I...
Power Apps
Unanswered

Gallery show or hide Items

(0) ShareShare
ReportReport
Posted on by

I have a gallery with Items bound to Collection

{ QuestionId: 1 , NextQuestionYes:2, ParentQuestion: , Visible:1 , Answer: Yes/No} 

{ QuestionId: 2 , NextQuestionYes:3, ParentQuestion1: , Visible:0 ,Answer: Yes/No} 

{ QuestionId: 3 , NextQuestionYes:4, ParentQuestion: 2, Visible:0 ,Answer: Yes/No} 

{ QuestionId: 4 , NextQuestionYes:, ParentQuestion: 3, Visible:0 ,Answer: Yes/No} 

 

I would like to initially show Q1 and then when he answers Q1 with Yes, Question 2 will be shown along with Q1. When Q2 in answered with Yes , Q1,2,3 will be shown. If he answers No to Q1 then the brnaching stops there. 

I will have multiple top level questions with user going through branching based on his answer. 

How can we do this, I tried maintaining two collections and use the filtered collection with Visible = 1 as items to Gallery but it resets user answer after each refresh.  Looking to see if we can use the original collection and somehow show or hide gallery item based on Visible property instead of filtering and creating a new collection. 

Categories:
I have the same question (0)
  • Ami K Profile Picture
    15,687 Super User 2024 Season 1 on at

    @Cnivas1 - one method based on what I think you're trying to do:

     

    1. Create the following Collection:

     

    ClearCollect(
     MyCollection,
     [
     {
     QuestionId: 1,
     Answer: [
     "Yes",
     "No"
     ],
     Display: true
     },
     {
     QuestionId: 2,
     Answer: [
     "Yes",
     "No"
     ],
     Display: false
     },
     {
     QuestionId: 3,
     Answer: [
     "Yes",
     "No"
     ],
     Display: false
     },
     {
     QuestionId: 4,
     Answer: [
     "Yes",
     "No"
     ],
     Display: false
     }
     ]
    )

     

    2. Set the Items property of the Gallery control to:

     

    Filter(
     MyCollection,
     Display
    )

     

    3. Embed a Dropdown control inside the Gallery (so the control is duplicated per the number of items in the Gallery).

     

    4. Set the Default property of the Dropdown to ""

     

    5. Set the AllowEmptySelection property of the Dropdown to true.

     

    6. Set the Items property of the Dropdown control to:

     

    ThisItem.Answer

     

    7. On the OnChange property of the Dropdown control, enter:

     

     

    UpdateIf(
     MyCollection,
     QuestionId = ThisItem.QuestionId + 1,
     {Display: Self.Selected.Value = "Yes"}
    )

     

  • RogierE Profile Picture
    879 Moderator on at

    So what I would advice you to do is to start with a collection to collect your Questions and answers with the clearcollect. I added some question descriptions and blank values were necessary:

     

    ClearCollect(colQuestions,[{ Question:"Question description",QuestionId: 1 , NextQuestionYes:2, ParentQuestion:Blank() , Visible:true , Answer: ""},
    { Question:"Question description",QuestionId: 2 , NextQuestionYes:3, ParentQuestion:1 , Visible:false ,Answer: ""},
    { Question:"Question description",QuestionId: 3 , NextQuestionYes:4, ParentQuestion: 2, Visible:false ,Answer: ""},
    { Question:"Question description",QuestionId: 4 , NextQuestionYes:Blank(), ParentQuestion: 3, Visible:false ,Answer: ""} ])
     
    Now once you do that you can create a Gallery with colQuestions as the Items source, and use the Question column for displaying your question and a dropdown for selecting the answer Yes or No
     
    The Dropdown would have 
    ["Yes","No"
    as Items and
    [ThisItem.Answer]
    as DefaultSelecteditems.  
     
    Now to save your answer, you would add this to the OnChange of the Dropdown:
    UpdateIf(colQuestions,QuestionId=ThisItem.QuestionId,{Answer:Self.Selected.Value})
     
    Then select all of the controls in your Gallery and add this to the Visible property:
    LookUp(colQuestions,QuestionId=ThisItem.ParentQuestion,Answer)="Yes" || ThisItem.QuestionId=1
     
    Note: the visible column in your collection is not necessary as a question will be shown if it is Question1 or if the parent Question has been answered positively.
     
    Please like the reply and accept it as the solution if the answer is what you were looking for.

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 April Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Apps

#1
Vish WR Profile Picture

Vish WR 421

#2
Valantis Profile Picture

Valantis 405

#3
timl Profile Picture

timl 337 Super User 2026 Season 1

Last 30 days Overall leaderboard