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 / Variables inside a Gal...
Power Apps
Answered

Variables inside a Gallery

(0) ShareShare
ReportReport
Posted on by Microsoft Employee

So I have 2 buttons inside each item of a gallery, and when I press one, it disappears and another one appears thorugh the use of 2 variables I created with Set/UpdateContext (I can use both of them and it doesn't change anything), but when I have more than 1 item in the gallery ALL of the buttons "of the same type" disappear instead of the disappearing on just one item, what can I do to fix this?

Categories:
I have the same question (0)
  • Pstork1 Profile Picture
    69,657 Most Valuable Professional on at

    I don't think there is any way to get around that behavior.  The variables are scoped for the whole screen, so when you set them in one item the effect covers all the records.  The only workaround I can think of is to add a column to the datasource when you load it.  That will add a field to each record.  Use that field to store the value for which button should show in that record instead of the variable.

    -------------------------------------------------------------------------
    If I have answered your question, please mark your post as Solved.
    If you like my response, please give it a Thumbs Up.

  • Verified answer
    v-xida-msft Profile Picture
    Microsoft Employee on at

    HI @Anonymous ,

    Do you want to use variables to control the visible of the two buttons within your Gallery?

     

    I agree with @Pstork1 's thought almost. The variables you set up within an app would be scoped to current screen (Context variable) or the whole app (Global variable). If you use the variable to control the visible of the two buttons, once the variable changes, all related items which references the variale would be affected within your Gallery.

     

    As an alternative solution, you could consider add a column (Called "Status") within your data source to store the clickable status value. When you click one of the two buttons within your Gallery, update the  "Status" column value based on the clicked button. Then visible the two buttons based on the "Status" column value.

     

    I assume that you add a "Status" column (Text type column, default value is Blank) in your data source, when you click the first button, update "Complete" value to the "Status" column in your data soufce.

    I have made a test on my side, please take a try with the following workaround:

    Set the OnSelect property of the First button in your Gallery to following:

    Patch(
     'YourDataSource',
     ThisItem,
     {
     Status: "Complete"
     }
    )

    Set the Visible property of the First button to following:

    If(
     IsBlank(ThisItem.Status),
     true,
     false
    )

    Set the Visible property of the Second Button in your Gallery to following:

    If(
     ThisItem.Status = "Complete",
     true,
     false
    )

    Please consider take a try with above solution, then check if the issue is solved.

     

    More details about the Patch function, please check the following article:

    Patch function

     

    Best regards,

  • krishangopi Profile Picture
    33 on at

    Hello,

    I came across a similar requirement and couldn't find any better solution than what has already been proposed in this thread. I felt it's worth putting a feature request for this and have raised an idea: 

    https://powerusers.microsoft.com/t5/Power-Apps-Ideas/Allow-variables-at-gallery-item-level-scope/idi-p/1447718#M35356

     

    Please vote of you agree!

     

    Regards,

    Krishan

  • zznmfc123 Profile Picture
    14 on at

    Related to this - it is a bit hacky - but you can add a hidden label holding a value to the gallery in question (in this case a boolean) and then drive the required behaviour like that (in this case to selective control visibility of a button on each row).

     

    For example:

    IVS_ShowIndRecSave_Hidden_Btn.Text

    If(CountRows(SomeStuff) + CountRows(SomeMoreStuff)<> 0,true,false)

     

    Then simply set the visible property of the (row level) control (or whatever) to the name of your hidden label, in this case IVS_ShowIndRecSave_Hidden_Btn

    IVS_ShowIndRecSave_Hidden_Btn

     

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 Winners!

Congratulations to our community stars!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Congratulations to the July Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 329 Most Valuable Professional

#2
11manish Profile Picture

11manish 209 Super User 2026 Season 2

#3
Mohsin Ali Profile Picture

Mohsin Ali 179

Last 30 days Overall leaderboard