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 / Filter a Gallery to Sh...
Power Apps
Answered

Filter a Gallery to Show Only Newest Record

(0) ShareShare
ReportReport
Posted on by

Hello and good morning,
I have a situation where a person can update values on a form and when submitted doesn't overwrite the record but creates a new record in the SharePoint list. What this does is create multiple records for the same user in the gallery.
Is there a way to filter the gallery to only show the last or latest record? 
Here is my current filter for my gallery. 
Thank you @Amik 

 

With(
    {
        _pre_filtered_data: Filter(
            'BLC Goal Tracking',
            Len(txtSearchBox.Text) = 0 || StartsWith(
                Colleague.DisplayName,
                txtSearchBox.Text
            )
        )
    },
    Sort(
        _pre_filtered_data,
        Colleague.DisplayName,
        SortOrder.Ascending
    )
)
Categories:
I have the same question (0)
  • mmbr1606 Profile Picture
    14,629 Super User 2026 Season 1 on at

    hey @ChrisL58 

     

    can u tr this:

    With(
     {
     _pre_filtered_data: Filter(
     'BLC Goal Tracking',
     Len(txtSearchBox.Text) = 0 || StartsWith(
     Colleague.DisplayName,
     txtSearchBox.Text
     )
     )
     },
     ForAll(
     GroupBy(
     Sort(
     _pre_filtered_data,
     Created,
     SortOrder.Descending
     ),
     "Colleague.DisplayName",
     "ItemsByUser"
     ),
     First(ItemsByUser)
     )
    )
    

     

    you might need to rename to your needs.

     

    Let me know if my answer helped solving your issue.

    If it did please accept as solution and give it a thumbs up so we can help others in the community.



    Greetings

  • anandm08 Profile Picture
    1,936 Super User 2024 Season 2 on at

    hi @ChrisL58 

    try this:

    With(
     {
     _pre_filtered_data: Filter(
     'BLC Goal Tracking',
     Len(txtSearchBox.Text) = 0 || StartsWith(
     Colleague.DisplayName,
     txtSearchBox.Text
     )
     ),
     _grouped_data: GroupBy(
     _pre_filtered_data,
     "Colleague.DisplayName",
     "UserRecords"
     ),
     _latest_records: ForAll(
     _grouped_data,
     Last(SortByColumns(UserRecords, "Created", Descending))
     )
     },
     Sort(
     _latest_records,
     Colleague.DisplayName,
     SortOrder.Ascending
     )
    )
  • ChrisL58 Profile Picture
    on at

    Hello and thank you for your response.
    There are errors in the logic.
    "Expected Table Value"

    ChrisL58_2-1717761031845.png

     

     

  • ChrisL58 Profile Picture
    on at

    Hello and thank you for your response.
    I am seeing errors.

    First Error: Name isn't valid. '_pre_filtered_data' isn't recognized.

    Second Error: Name isn't valid. '_grouped_data' isn't recognized.
    Third Error: Name isn't valid. 'UserRecords' isn't recognized.

     

    ChrisL58_1-1717760601874.png

     

  • anandm08 Profile Picture
    1,936 Super User 2024 Season 2 on at

    can you share the error

  • ChrisL58 Profile Picture
    on at

    Hello and thank you for your response.
    "you might need to rename to your needs."

    I am a bit new to this so please explain.

  • ChrisL58 Profile Picture
    on at

    I shared the error message.
    Did you receive?

  • Verified answer
    Ami K Profile Picture
    15,687 Super User 2024 Season 1 on at

    @ChrisL58 - I think the below is what you're trying to do:

     

    With(
     {
     _pre_filtered_data: Filter(
     'BLC Goal Tracking',
     Len(txtSearchBox.Text) = 0 || Colleague.DisplayName = txtSearchBox.Text
     )
     },
     ForAll(
     GroupBy(
     AddColumns(
     _pre_filtered_data,
     ColleagueDisplayName,
     Colleague.DisplayName
     ),
     ColleagueDisplayName,
     _items
     ),
     First(
     Sort(
     _items,
     Created,
     SortOrder.Descending
     )
     )
     )
    )

     

    Notes:

     

    1. This solution is not delegable with any data source. However, this is mitigated somewhat so long as a Filter is applied prior to running the rest of the functions, and the output of that Filter does not exceed 500 rows (or max 2000 if increased via Settings).

    2. Please be mindful that "shaping" or "transform" functions like AddColumns or GroupBy modify the table schema of your Gallery. If you have an Edit Form control which is bound to a selected item in the Gallery, this will result in an error. 

    The reason is because the table schema used in the DataSource and the Item property of the Edit Form must be the same. Given we have just modified the table schema in the Gallery, the table is now different to what the Item property of the Edit Form is expecting.

     

    The typical workaround is to use a LookUp function in the Item property of your Edit Form to return the correct record:

     

    LookUp(
     'BLC Goal Tracking',
     ID = 'Your Gallery'.Selected.ID

     

  • ChrisL58 Profile Picture
    on at

    Thank you Amik,
    This logic worked but for some reason it doesn't sort correctly.

    I tried both Aescending and Descending

    Thank you for the explanation as well.

    ChrisL58_1-1717767080471.png

     

  • ChrisL58 Profile Picture
    on at

    I also modified the Item to use the lookup you suggested, which works. Thankyou.
    Glad to know that this method is preferred over using <galleryName>.Selected.

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

These are the community rock stars!

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 305 Most Valuable Professional

#2
11manish Profile Picture

11manish 212

#3
Valantis Profile Picture

Valantis 167

Last 30 days Overall leaderboard