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 / First function in a ga...
Power Apps
Unanswered

First function in a gallery not consistent

(0) ShareShare
ReportReport
Posted on by 4

Scenario: I have a screen that loads a gallery with values from a filtered query.  The gallery is hidden by default, and its visible property is set to true when it is populated with results.  This is checked by seeing if the value of the key gallery item’s label is equal to the value I’m expecting  (lblName.Text = vAccountName).

The first time the screen is shown, everything works fine.  For example, the gallery loads with 20 items.  I select a row deep in the gallery (say row 18) and move off the screen to something else.  If I navigate back to the screen and this time the filtered query has less results than the first time (say returning 1 row instead of 20), the First([]) function does not fire.  The results are that lblName.Text would be blank even though the gallery has items.

If I back up and try it again, it works.

 

The gallery’s default is set to First([])

The OnVisible event of the screen resets the gallery in question

 

Has anybody else seen this behavior, or is there another way to ensure the first row of a gallery is selected upon population of data?

Categories:
  • v-xida-msft Profile Picture
    Microsoft Employee on at

    Hi @Woody ,

    Could you please share more details about the formula within the Items property of the Gallery?

    Do you want the first item within the Gallery to be selected?

    If you want the first item within the Gallery to be selected when your Gallery populated with data, I have made a test on my side, please take a try with the following workaround:8.JPG

     

    9.JPG

    Set the OnVisible property of the first screen of my app to following:

    Clear(RecordsCollection);
    ClearCollect(RecordsCollection, '20190211_case5')

    On your side, you should set the OnVisible property of the screen which contains the Gallery control:

    Clear(RecordsCollection);
    ClearCollect(RecordsCollection, 'YourDataSource')

    Set the Default property of the Gallery to following:

    First(RecordsCollection)

    Set the Items property of the Gallery to following:

    SortByColumns(
    Filter(RecordsCollection, StartsWith(Title, TextSearchBox1.Text)),
    "Title", If(SortDescending1, Descending, Ascending)
    )

    On your side, you should type:

    SortByColumns(
     Filter(RecordsCollection, StartsWith(Title, TextSearchBox1.Text)), /* <-- Use RecordsCollection as data source within your Gallery instead of your original data source*/
     "Title", If(SortDescending1, Descending, Ascending)
    )

    Please check the attached GIF screenshot for more details:

     

    Best regards,

    Test.gif
  • iAm_ManCat Profile Picture
    18,256 Most Valuable Professional on at

    Hi,

     

    Did you check/test that your reset is not clearing the Default value (rather than 'resetting to default') when reset as it may not be able to check First() during the reset action.

     

    I would try to set a variable on App start
    Set(FirstGalleryItem, First(DataSourceThatGalleryUses))

     

    Then for your gallery default have it set to FirstGalleryItem - this won't be affected by any reset function performed on the gallery itself.

     

    I hope this helps towards your solution 🙂

  • Woody Profile Picture
    4 on at

    So, I'm not using a collection because the data set in this case is filtering 35,000 records, and  I don't want to have to download the full data set down to someones device.  The fields used in the filtering vary depending on the logic of the prior form.  

     

    The bigger issue that I'm having is that even though the records are changing in the gallery, when I come back to it, the gallery still is thinking that a record way at the bottom is still selected (even if there is no record at that index anymore)

  • Woody Profile Picture
    4 on at

    I'm probably not explaining my situation very well.  The first function works just fine either the first time the screen is run, if the data set has been cached in the past, or the results return more rows than the row that was previously selected. 

     

    However, if during the same session with the app, you navigate to the screen with this gallery and the result of the filters return less rows than where you might've clicked in the list the first time, nothing is selected (first or otherwise). 

     

    I really think this is a bug.

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

Leaderboard > Power Apps

#1
11manish Profile Picture

11manish 432 Super User 2026 Season 2

#2
Mohsin Ali Profile Picture

Mohsin Ali 347

#3
WarrenBelz Profile Picture

WarrenBelz 254 Most Valuable Professional

Last 30 days Overall leaderboard