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 / Reduce Table to Latest...
Power Apps
Answered

Reduce Table to Latest Record for Each User

(0) ShareShare
ReportReport
Posted on by Microsoft Employee

I am working on a PowerApp that pulls data from an Azure SQL instance.  This table has multiple records per person and I would like to create a collection of just the latest record per user.  Example:

 

CurrentTable

NameApplicationStateDateRecordCreated
ShaneTerminated2022-05-22
MarryPending2022-07-15
BobActive2022-06-11
SonyaActive2022-05-22
ShaneActive2022-07-05
BobPending2022-05-22
MarryTerminated2022-05-22

 

I would like to reduce CurrentTable down to the latest records per user, NewTable:

 

NewTable

NameApplicationStateDateRecordCreated
ShaneActive2022-07-05
BobActive2022-06-11
MarryPending2022-07-15
SonyaActive2022-05-22

 

I have tried nested filtering and using GroupBy within a filter.  I feel like I've gotten close but can't quite get what I'm looking for.  Thank you in advance.

Categories:
I have the same question (0)
  • RandyHayes Profile Picture
    76,299 Super User 2024 Season 1 on at

    @Anonymous 

    Please consider the following Formula:

    ForAll(
     GroupBy(
     Sort(CurrentTable, DateRecordCreated, Descending),
     "Name",
     "_items"
     ),
     {Name: Name,
     ApplicationState: First(_items).ApplicationState,
     DateRecordCreated: First(_items).DateRecordCreated
     }
    )

    This would return a table like you are looking for.

     

    I hope this is helpful for you.

  • Community Power Platform Member Profile Picture
    Microsoft Employee on at

    That looks interesting, I will try to apply that now.  The real table I'm working with has many more columns.  Would you mind explaining to me what the code is doing?

     

    Thanks

  • Verified answer
    RandyHayes Profile Picture
    76,299 Super User 2024 Season 1 on at

    @Anonymous 

    What the formula is doing is to first sort the table by the created date.  Then it groups those results by the "Name" column.  All associated records will then be in the "_items" column.  Since the list was sorted in descending date order, the first record of each individual group will be the most recent.

    So, the ForAll then is returning the table of records that would be the group name, and then the first record values.

     

    If you have a lot of columns to contend with, then you can change to the following Formula so that you don't need to specify each column by hand:

    ForAll(
     GroupBy(
     Sort(CurrentTable, DateRecordCreated, Descending),
     "Name",
     "_items"
     ),
     Patch({Name: Name}, First(_items))
    )

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

#2
11manish Profile Picture

11manish 214 Super User 2026 Season 2

#3
Mohsin Ali Profile Picture

Mohsin Ali 185

Last 30 days Overall leaderboard