Skip to main content
Community site session details

Community site session details

Session Id : 17Cl3Yxu7HVX9pnUvgWB7L
Power Apps - Building Power Apps
Answered

Getting Last Record from SQL Database

Like (0) ShareShare
ReportReport
Posted on 30 Mar 2020 09:26:46 by 144

Hi all!

 

I have what I am sure is a very quick and easy question!

 

I have a SQL table with a list of visits to customers.

What I need to do is pull back the last record for that customer and then show the date column

 

For example:

custnamecustiddate
Comp1120/02/2020
Comp1120/03/2020
Comp2219/01/2020
Comp2227/02/2020
Comp3330/03/2020

 

So for instance I want to do a Lookup for custid = 2 and Return the last entered date column.
This would return 27/02/2020, is this possible.

 

The only way I have made this happen so far is with the following code:

 

ClearCollect(
 LastVisit,
 LastN(
 Filter(
 '[dbo].[visitlog]',
 custid = Text(ThisItem.ID)
 ),
 1
 ).date

 

 

Obviously this then adds it to a collection, I can then return that collection into a Drop down and Then that drop down into a Label Field.

This just seems a long winded way to get what I need.

 

Any help is much appreciated! 

 

Cheers,
Danny

  • MrDannyHarry Profile Picture
    144 on 30 Mar 2020 at 09:58:39
    Re: Getting Last Record from SQL Database

    @WarrenBelz 

     

    New it would be something simple!!!

    Thanks for the tip on the column name! Will change this as well.

  • Verified answer
    WarrenBelz Profile Picture
    148,878 Most Valuable Professional on 30 Mar 2020 at 09:49:40
    Re: Getting Last Record from SQL Database

    Hi @MrDannyHarry ,
    I am a SharePoint user, but this may work (it does on my large test list).
    Also, date is not a good title for a field - it is a reserved word.

    First(
     Sort(
     Filter(
     '[dbo].[visitlog]',
     custid = Text(ThisItem.ID)
     ),
     date,
     Descending
     )
    ).date

     

    Please click Accept as solution if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it Thumbs Up.

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

Announcing our 2025 Season 2 Super Users!

A new season of Super Users has arrived, and we are so grateful for…

Paul Stork – Community Spotlight

We are honored to recognize Paul Stork as our July 2025 Community…

Congratulations to the June Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 791 Most Valuable Professional

#2
MS.Ragavendar Profile Picture

MS.Ragavendar 410 Super User 2025 Season 2

#3
mmbr1606 Profile Picture

mmbr1606 275 Super User 2025 Season 2