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 / SQL Table - Get Most R...
Power Apps
Answered

SQL Table - Get Most Record for Each Unique ID

(0) ShareShare
ReportReport
Posted on by

Data:  SQL Table with 2 columns - ID & Date.  There are approx 15 distinct IDs in the table, repeated a lot with different dates. In power apps, I'd like to see the most recent date for each ID in the table. I can't figure out the formula combination needed for this - any help ?

What i'd like it to look like:

ID | Date
1 | 5/7/2019
2 | 5/6/2019

Etc

Categories:
I have the same question (0)
  • mogulman Profile Picture
    764 on at

    I would create a view and do a filter in PA.  I haven't tried but the view should look something like this.  You may have to experiment with syntax.

     

    CREATE VIEW [dbo].[MyView]
    AS
    SELECT Id
     ,RefDate
     ,ROW_NUMBER()
    OVER(
    	PARTITION BY id
    	ORDER BY RefDate DESC) AS Rn
    FROM MyTable

    Rn will equal 1 for the max RefDate for each unique Id.  Filter view where Rn = 1.

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

    Hi @powerappsUser31 ,

    Do you want to get the most recent date for each ID in your SQL Table within your SQL Table?

     

    Based on the needs that you mentioned, I think the combination of GroupBy function, AddColumns function and DroColumns function could achieve your needs.

     

    I have made a test on my side, please take a try with the following workaround:11.JPG

    On your side, you could add a Data Table control within your app, then set the Items property to following:

    DropColumns(
    AddColumns(
    GroupBy('[dbo].[YourSQLTable]', "ID", "GroupData"),
    "Date", /* <-- added new column */
    First(SortByColumns(GroupData,"Date", Descending)).Date /* <-- Date represents the Date column in your SQL Table */
    ),
    "GroupData"
    )

    then within the Data Table, enable the ID column and Date column to display.

     

    More details about the GroupBy function, AddColumns function and DropColumns function, please check the following article:

    GroupBy function, AddColumns function and DropColumns function

     

    Best regards,

  • timl Profile Picture
    37,152 Super User 2026 Season 1 on at

    Hi @powerappsUser31 

    If possible, I would recommend @mogulman's suggestion. I have used this exact technique in my own apps.

    The benefit of using a view is that it'll be faster than a pure PowerApps solution. Also, it'll be more immune to delegation problems as the number of records in your table increases.

     

  • mogulman Profile Picture
    764 on at

    In general, I want to make the PowerApp as simple as possible.  SQL Server is a very powerful and robust data storage solution.  My view is SQL Server or Azure SQL DB should be the go to solution for any significant business application.  Whenever possible use SQL Server to solve a problem.   My only disappointment with PowerApps and SQL Server is PowerApps doesn't support SQL Server triggers.  This needs to be fixed.

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Users!

Kudos to our 2025 Community Spotlight Honorees

Congratulations to our 2025 community superstars!

Congratulations to the April Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Apps

#1
Vish WR Profile Picture

Vish WR 860

#2
Valantis Profile Picture

Valantis 548

#3
Haque Profile Picture

Haque 417

Last 30 days Overall leaderboard