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 / Check and patch and lo...
Power Apps
Answered

Check and patch and lookup question

(0) ShareShare
ReportReport
Posted on by Microsoft Employee

Hey guys!

 

I have an app that collects a bunch of info with this code, that repeats itself for every row of data, I have 16 rows of data that are collected:

 

ClearCollect(Collection1, 
 {
 Category: (Category.Selected.Result),
 Base: Base1.Text,
 Status: Estatus1.Value,
 Ticket: Value(Ticket1.Text),
 Comment: Coment1.Text},

 

And I have this code to patch it to a sharepoint list:

 

ForAll(Collection1, Patch(Registros, Defaults(Registros), 
{Title: Base, Categoria: Category, Estatus: Status, Tickets: Ticket, Comentario: Comment}));
Refresh(Registros);SortByColumns(Registros,"Modified",Ascending);Navigate(Inicio, ScreenTransition.Fade)

 

 My question is if there is a way that the info is patched only if the Ticket does not exist on the sharepoint list, and if it does exist, do not patch that particular row of data.

 

Another thing that I noticed is that, i might have several records of the same category, for example Category 1 can have 5 records each with different data on the sharepoint list. What I'm trying to do is bring the latest value of that category(database in this case) but it does not bring me the latest value, it brings me the first one. My sharepoint list is sorted by date. Do you guys have an idea how can I resolve this?

This is the code that I'm using:

 

LookUp('Registros',
NombreBase = Base1.Text,
Tickets)

 

Categories:
  • WarrenBelz Profile Picture
    156,963 Most Valuable Professional on at

    Hi @Anonymous ,

    Which field in the collection is the unique identifier of the ticket to determine whether it exists in the SharePoint list?

  • Community Power Platform Member Profile Picture
    Microsoft Employee on at

    Sorry I misunderstood, it would be the ticket. 

    Ticket: Value(Ticket1.Text)

     

  • WarrenBelz Profile Picture
    156,963 Most Valuable Professional on at

    Hi @Anonymous ,

    I cannot test this, but the idea would be something like

    ForAll(
     Filter(
     Collection1,
     Not(
     Ticket in [@Registros].Tickets
     )
     ), 
     Patch(
     Registros, 
     Defaults(Registros),
     {
     Title: Base, 
     Categoria: Category, 
     Estatus: Status, 
     Tickets: Ticket, 
     Comentario: Comment
     }
     )
    )

     

    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.

  • v-siky-msft Profile Picture
    Microsoft Employee on at

    Hi @Anonymous ,

     

    The lookup function finds the first record in a table that satisfies a formula.

    If you want to find the latest value, please try to use SortbyColumns function to sort the table by created column in descending order, then the latest value is the first record.

    First(SortByColumns(Filter('Registros', NombreBase = Base1.Text, Tickets),"Created",Descending))

    Hope this helps.

    Sik

  • Community Power Platform Member Profile Picture
    Microsoft Employee on at

    Hi @WarrenBelz !

     

    I tried it but when ticket exists it doesn't save the whole collection, and I want no to save just that row of date, from what I see on the formula I would have to add every collect row so that it just applies to the ones that match, and if it match do not save.

     

    Am I right?

     

    Thanks for your insight!

  • Community Power Platform Member Profile Picture
    Microsoft Employee on at

    Hi @v-siky-msft !

     

    I tried it but it tells me that a text value was expected, I do not understand, I'm trying to retrieve a number. 

     

    First(SortByColumns(Filter(Registrosv2; Título = Base1.Text; Tickets);"Created";Descending))

     

    Thanks for your response!

  • WarrenBelz Profile Picture
    156,963 Most Valuable Professional on at

    Hi @Anonymous ,

    I am a little confused - your first requirement was

     

    My question is if there is a way that the info is patched only if the Ticket does not exist on the sharepoint list, and if it does exist, do not patch that particular row of data.

    Now you are saying

    I tried it but when ticket exists it doesn't save the whole collection, and I want no to save just that row of date, from what I see on the formula I would have to add every collect row so that it just applies to the ones that match, and if it match do not save.

     

    There will be a solution to this - I just need to kn ow exactly what you are trying to achieve.

  • Community Power Platform Member Profile Picture
    Microsoft Employee on at

    Hi @WarrenBelz ! Indeed, my mistake,

     

    The thing is that the collection has 16 rows of data.

    So for example, if the ticket no. exists on row 14, I need not to save that row but still save the other 15 rows of data. I do not know if I need to do that check  and arguments on the collection formula, rather than the patch formula. The code that you kindly gave me it does check if the ticket number exists and it does work. But for example it is on row 14 it will stop the patch there and it will not save row 14, 15, and 16. And if the ticket no. is found on row1 it wont save anything.

     

    I'm sorry if my explanations are incorrect or not precise. I appreciate your help.

     

    Sergio 

  • WarrenBelz Profile Picture
    156,963 Most Valuable Professional on at

    Thanks @Anonymous ,

    I am surprised at that result, but as I said, I had not tested it. This should work however

    ClearCollect(
     colTemp,
     Filter(
     Collection1,
     Not(
     Ticket in [@Registros].Tickets
     )
     )
    ); 
    ForAll(
     colTemp, 
     Patch(
     Registros, 
     Defaults(Registros),
     {
     Title: Base, 
     Categoria: Category, 
     Estatus: Status, 
     Tickets: Ticket, 
     Comentario: Comment
     }
     )
    );
    Clear(colTemp)

     

    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.

  • v-siky-msft Profile Picture
    Microsoft Employee on at

    Hi @Anonymous ,

     

    Sorry, my mistake. Please try this:

    First(SortByColumns(Filter(Registrosv2; Título = Base1.Text);"Created";Descending)).Tickets

    Sik

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

Leaderboard > Power Apps

#1
11manish Profile Picture

11manish 221 Super User 2026 Season 2

#2
WarrenBelz Profile Picture

WarrenBelz 188 Most Valuable Professional

#3
Mohsin Ali Profile Picture

Mohsin Ali 120

Last 30 days Overall leaderboard