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 filtering on t...
Power Apps
Answered

Gallery filtering on the latest record

(0) ShareShare
ReportReport
Posted on by 7

Hi All,

 

I have a SharePoint list that records the data loads between databases. This contains all the records for historic loads but I want to show the latest record for each job in a gallery.

 

I have the following fields :

 

Title - Name of the job

Start Time - Date/Time field

End Time - Date/Time field

Elapsed Time - Calc based on the Start and End Time

Rows Updated - Number

Status - Choice field

 

My logic in the gallery item was originally :

 

SortByColumns(Filter([@'SharePointListName'],StartsWith(Title,TextSearchBox1.Text)),"Title",If(SortDescending1,Descending,Ascending))

 

This returned all records, however i only need the latest record. The jobs dont always run on the same day so i need the max record i think and i need to apply a group by? These are the bits i'm not sure on. I have done the group by but it only returns the Title field : 

 

GroupBy(
SortByColumns(
Filter([@'SharePointListName'],StartsWith(Title,TextSearchBox1.Text)),
"Title",
If(SortDescending1,Descending,Ascending)),
"Title","Grouped")

 

How do i add the latest record fields (Start Time, End Time, Elapsed Time, Rows Updated, Status) to the gallery?

 

Thanks,

 

Matt

Categories:
I have the same question (0)
  • v-xiaochen-msft Profile Picture
    Microsoft Employee on at

    Hi @Vega ,

     

    Could you tell me:

    1. What field is used to find the latest record?
    2. What is SortDescending1 in your formula?

     

    I assume:

    1. Use ID field to find the latest record.
    2. The value in SortDescending1 is true.

     

    If the above assumptions are true, the point is to use the sortbycolumns() function to sort the ID field from high to low, and then use lookup() function to get the latest record.

    I've made a test for your reference:

     

    1\ Show my data in list:

    v-xiaochen-msft_0-1605863188445.png

     

     

    2\ Add a gallery control to screen and set its Items property to:

    SortByColumns(
    
     Filter(
    
     ForAll(
    
     Distinct(
    
     SharePointListName,
    
     Title
    
     ),
    
     LookUp(
    
     SortByColumns(
    
     SharePointListName,
    
     "ID",
    
     Descending
    
     ),
    
     Result = Title
    
     )
    
     ),
    
     StartsWith(
    
     Title,
    
     TextSearchBox1.Text
    
     )
    
     ),
    
     "Title",
    
     If(
    
     SortDescending1, //The value of ‘SortDescending1’ is true here.
    
     Descending,
    
     Ascending
    
     )
    
    )

     

    3\ The result are as follow:

    v-xiaochen-msft_1-1605863188447.png

     

    v-xiaochen-msft_2-1605863188448.png

     

     

    Best Regards,

    Wearsky

  • Vega Profile Picture
    7 on at

    Thanks so much for the response, i might not have been very clear but i only want to display the latest run for each job in the gallery. So, based on your data, it should look like :

    Job 1 - Start Time : 05/11/2020

    Job 2 - Start Time : 14/11/2020

     

    Thanks,

    Matt

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

    Hi @Vega ,

     

    Could you tell me:

    • Do you want the table to be sorted in ascending order by Title field?  Look like my picture below:

    v-xiaochen-msft_0-1606097906724.png

     

     

    If so , please set the value of SortDescending1 to false .

    In my code, the value of SortDescending1 is true. I sort the table in descending order.

    v-xiaochen-msft_1-1606097906726.png

     

     

    Please try the following code:

    SortByColumns(
    
     Filter(
    
     ForAll(
    
     Distinct(
    
     SharePointListName,
    
     Title
    
     ),
    
     LookUp(
    
     SortByColumns(
    
     SharePointListName,
    
     "ID",
    
     Descending
    
     ),
    
     Result = Title
    
     )
    
     ),
    
     StartsWith(
    
     Title,
    
     TextSearchBox1.Text
    
     )
    
     ),
    
     "Title",
    
     If(
    
     SortDescending1, //The value of ‘SortDescending1’ is false here.
    
     Descending,
    
     Ascending
    
     )
    
    )

     

    If my guess is wrong, please tell me your needs in more detail, and I will be happy to solve the problem for you.

     

    Best Regards,

    Wearsky

  • Vega Profile Picture
    7 on at

    This is great! I 've actually sorted by the Start Time rather than the ID as in my POC example I have retro added records. But your thinking was correct. Once again, big thanks!!

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 356 Most Valuable Professional

#2
11manish Profile Picture

11manish 225 Super User 2026 Season 2

#3
Mohsin Ali Profile Picture

Mohsin Ali 211

Last 30 days Overall leaderboard