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 / New or update latest r...
Power Apps
Answered

New or update latest record

(0) ShareShare
ReportReport
Posted on by 113

Hi,

 

I have a dataverse table where I have an unique ID with the following form: Date+Name.

Everytime, an user clicks on a button on my app, I got the data with the following patch:

 

Patch('SAB cout projet';
Defaults('SAB cout projet');
{'Month and year': Text(ComboBoxPMois_1.Selected.Result)};
{Month: TitleMois.Text};
{Year: TitleYear.Text};
{Date: GalleryDateMasque.Selected.Date};
{'Total month': Sum ((Sum(GalleryDataBudgetR.AllItems; BodySalaire.Text)); (Sum(BodyLicencesPVPA)); (Sum(BodyLicencePVJ)); (Sum(BodyLicencesPVC)); (Sum(BodyLicencesPVPB)); (Sum(BodyAchats)); (Sum(BodyDeplacements)))};
{Salaire: Sum ((Sum(GalleryDataBudgetR.AllItems; BodySalaire.Text)))};
{Achats: Sum ((Sum(GalleryDataBudgetR.AllItems; BodyAchats.Text)))};
{Deplacements: Sum ((Sum(GalleryDataBudgetR.AllItems; BodyDeplacements.Text)))};
{Licences: Sum ((Sum(BodyLicencesPVPA)); (Sum(BodyLicencePVJ)); (Sum(BodyLicencesPVC)); (Sum(BodyLicencesPVPB)); (Sum(BodyAchats)); (Sum(BodyDeplacements)))};
{Projet:ComboBoxVProjets.Selected.Result};
{ID: Text(ComboBoxPMois_1.Selected.Result) & "-" & ComboBoxVProjets.Selected.Result})

 

But I will like to have the possibility to keep the latest record in case the row has the same ID. I tried by modifying the business rules and by going on the admin center. And I even activated the detection of the duplicate rows but I'll like to have an update or create button instead of that options.

Categories:
I have the same question (0)
  • LaurensM Profile Picture
    12,516 Moderator on at

    Hi

     

    You could fetch the most recently created record before patching to Dataverse:

     

    First(Sort('SAB cout projet', 'Created On', Descending))

     
    This function can then be used to check whether the id would be the same as the one that is about to be created.

  • fatimaandrea Profile Picture
    113 on at

    Hi, thanks for your answer @LaurensM . What I want is to create or update records. In case, an user registers a new record, I want to keep the one they're about to create and delete the latest record.

    In case the ID is a new one, I want to save the data

  • Verified answer
    LaurensM Profile Picture
    12,516 Moderator on at

    Is updating the previous one also a possibility instead of create & delete?
    With the code below you will update if the IDs match, otherwise you will add a new record.

     

     

    If(
    First(Sort('SAB cout projet', 'Created On', Descending)).ID = YourNewID,
    Patch('SAB cout projet', LookUp('SAB cout projet', ID = YourNewID), {your fields}),
    Patch('SAB cout projet', Defaults('SAB cout projet'), {your fields})
    )

     

     

     
    I hope this helps!

  • fatimaandrea Profile Picture
    113 on at

    Thank you so much ! That works !

     

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

#2
11manish Profile Picture

11manish 209 Super User 2026 Season 2

#3
Mohsin Ali Profile Picture

Mohsin Ali 179

Last 30 days Overall leaderboard