web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / Patch 2nd last Record ...
Power Apps
Unanswered

Patch 2nd last Record and create new record

(0) ShareShare
ReportReport
Posted on by 23

Hi Guys,

 i'm trying to update the 2nd last record in a Table with a date value. There is a service description with valid dates.

When the user creates a new service description, the most recent record should be updated with a valid until date and a new record needs to be created.

 

I tried this with two Patch Statements. The new record will be created but the most recent record will not be updated.

 

Could you help?

Whats wrong here?

 

 

Patch(
 UDID;
 Defaults(UDID);
 {
 until: DatePicker1_1.SelectedDate;
 ID: First(LastN(Gallery1.AllItems; 2)).ID /*Get 2nd last ID or Entry from Gallery */
 }
);;
Patch(
 UDID;
 Defaults(UDID);
 {
 bel: DetScr_BEL.Text; 
 INTERNALID: DetScr_DrpdDwn_UServcie.Selected.INTERNALID; 
 from: DatePicker1.SelectedDate;
 //until: DatePicker1_1.SelectedDate;
 ChangeUser: User().FullName;
 ID: Last(Sort(UDID;ID;SortOrder.Ascending)).ID + 1
 }
);;Refresh(popup_overview_1);;Reset(Gallery1)

 

 

If you have any idea, that would be great.

I am not really a software engenieer and hope you have a good idea. 

 

The two Semicolon are correct in this code because in germany there is no coma as seperator.

 

Regards

Sebi

Categories:
I have the same question (0)
  • Verified answer
    Devvj Profile Picture
    1,132 Super User 2024 Season 1 on at

    Hi,
    you would need to apply the logic in the first Patch in the second argument instead of the Default, since Default indicates that it should create a new record, so something like this maybe works:

    Patch(
     UDID;
     Lookup(UDID, UDID.ID = First(LastN(Gallery1.AllItems; 2)).ID) /*Get 2nd last ID or Entry from Gallery */;
     {
     until: DatePicker1_1.SelectedDate;
     }
    );;
    Patch(
     UDID;
     Defaults(UDID);
     {
     bel: DetScr_BEL.Text; 
     INTERNALID: DetScr_DrpdDwn_UServcie.Selected.INTERNALID; 
     from: DatePicker1.SelectedDate;
     //until: DatePicker1_1.SelectedDate;
     ChangeUser: User().FullName;
     ID: Last(Sort(UDID;ID;SortOrder.Ascending)).ID + 1
     }
    );;Refresh(popup_overview_1);;Reset(Gallery1)

     

    -------------------------------------------------------------------------
    If this is the answer for your question, please mark the post as Solved.
    If this answer helps you in any way, please give it a like.

  • Sebi087 Profile Picture
    23 on at

    Thanks, sometimes it could be so easy.

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

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 717 Most Valuable Professional

#2
Michael E. Gernaey Profile Picture

Michael E. Gernaey 329 Super User 2025 Season 2

#3
Power Platform 1919 Profile Picture

Power Platform 1919 268

Last 30 days Overall leaderboard