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.Selected chang...
Power Apps
Answered

Gallery.Selected changes in the backgorund because of sortbycolumns

(1) ShareShare
ReportReport
Posted on by Microsoft Employee

Hello!

I have an issue I don’t know how to solve. The app I am creating is a services desk-like app with a ticket system.

I have a gallery with tickets containing various information. The user can click on a ticket for navigation to a summary screen with more detailed information. Here I use Gallery1.Selected.X to display the information I want. On this screen the user can patch various values of the ticket. This has worked as intended until I created a sortbycolumns expression on the initial Gallery1.

 

Let’s say I click the top ticket in the gallery, I am navigated to the summary screen, and I patch a value for the ticket. In the Gallery1 on the previous screen this newly patched ticket has dropped to the bottom of the gallery because of the sortbycolumns, this works as intended. What dont work as intended is that the Galley.Selected value still refers to the top item of the Gallery1 and not the originally clicked item (now at the bottom).

 

I hope somebody can understand this explanation and help me out. This seems weird to me. The Gallery.Selected shouldn’t change just because there sorting do.

 

Cheers,
Joakim   

  

  

Categories:
  • Drrickryp Profile Picture
    Super User 2024 Season 1 on at
    What column are you sorting on?
  • Community Power Platform Member Profile Picture
    Microsoft Employee on at

    Here is the code for the Gallery:

    SortByColumns(
    SortByColumns(
     SortByColumns(
     Filter(
     AddColumns(
     GarantiErsattning,
     "Namn",
     LookUp(
     cashe_personuppgifter,
     ID = GarantiErsattning[@PersonuppgiftsID],
     Namn
     ),
     "Efternamn",
     LookUp(
     cashe_personuppgifter,
     ID = GarantiErsattning[@PersonuppgiftsID],
     Efternamn
     ),
     "Sortering",
     LookUp(
     cashe_flode,
     ID = GarantiErsattning[@StatusID],
     Sort
     )
     ),
     TI_sök_art.Text in Text(Artikelnummer),
     TI_sök_butik.Text in Text(Onskad_atgard) & Text(ArendeID),
     TI_sök_namn.Text in Text(Namn),
     TI_sök_efternamn.Text in Text(Efternamn),
     TI_sök_ärende.Text in Text(ArendeID),
     If(
     Checkbox_visa_avslutade.Value = false,
     "false",
     ""
     ) in Text(Avslutad)
     
     
     ),
     "Sortering",
     Ascending
     ),
     "Skapaddatum",
     Descending
    ), "Avslutad",
    Ascending)

    So when I patch a value in "Sortering" the order in the gallery changes, as it should. The issue is that the Gallery.Selected.X value changes too. 

     

    i.e.

     

    When I patch one value on my summary screen the order of the items in the gallery changes (which it should).
    But at the same time the value for Gallery.Selected changes without me clicking in the gallery.

    Im not sure I am explaining this all to well 🙂 Hope you understand.


     

  • Community Power Platform Member Profile Picture
    Microsoft Employee on at

    Clarification:

     

    If the sorting order of the gallery changes so does the value for Gallery.Selected on another screen, without me clicking on the gallery.

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

    Hi @Anonymous,

    Do you mean that the result the Gallery1.Selected formula returned would be changed when you made changes for any record within your data source?

    The user @aabrin has faced same issue with you, please check my response within the following thread:

    https://powerusers.microsoft.com/t5/General-Discussion/Bug-Gallery-with-calculated-values-will-lose-Selected-index-when/m-p/161150#M54252

     

    When you patch a value for "Sortering" column of the selected ticket record, the result the AddColumns formula returned would be updated, so the Gallery items would be refreshed/updated. In default, the first item of the Gallery control would be selected.

    If you want to not change the selected item within the Gallery control when you patch a value for any ticket record, please take a try with the following workaround:

    Set the OnSelect property of the Gallery control or the Navigate icon ( ">") button within the Gallery control to following formula:

    Set(CurrentSelectItem,ThisItem)

    Set the Default property of the Gallery control to following formula:

    CurrentSelectItem

    Set the TemplateFill property of the Gallery control to following (Set a background color for the selected item to distinguish😞

    If(ThisItem.ID=CurrentSelectItem.ID,RGBA( 255, 105, 180, 1 ),RGBA(0, 0, 0, 0))

     

    Best regards,

    Kris

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

11manish 409 Super User 2026 Season 2

#2
Mohsin Ali Profile Picture

Mohsin Ali 328

#3
WarrenBelz Profile Picture

WarrenBelz 252 Most Valuable Professional

Last 30 days Overall leaderboard