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 / Duplicates created in ...
Power Apps
Answered

Duplicates created in the target list for bulk updates using patch and forall

(1) ShareShare
ReportReport
Posted on by 12
Hi Everyone,
 
I am new to Power Apps, so please excuse me if this question has already been answered.

I have a source list where each record has certain columns, such as City and State, with predefined dropdown values. Once can update multiple rows at the same time, and ID is the unique identifier for each record. I have created a checkbox and am trying to perform a bulk update using a button.

These updates are then created in a target list. First, it needs to check if there is an existing record  for that source ID in the Title Column. If yes, it updates the existing record; if not, it creates a new record. The ID is the unique identifier in the target list. The logic works as expected for a single update. However, when performing a bulk operation (e.g., selecting three rows from the app), it creates 3 new rows in the target for the source record maximum ID(all 3 rows are not available in the target), and the other two rows are completely ignored.

Source List

ID Customer ID City State
12 ABC123 Buffalo NY
13 XYZ456 Orlando FL
 
 
Target List
 
ID Title Customer ID City State
01 13 XYZ456 Orlando FL
02 14 XYZ456 Orlando FL
 
 
ForAll(
    SelectedRecords,

    Notify("Processing record with Source ID: " & Text(ThisRecord.ID), NotificationType.Information);

    // Check if a record with the Title (mapped from Source ID) exists
    If(
        !IsBlank(LookUp(Target_List, Title = Text(ThisRecord.ID))), // Check existence
        // Update existing record if found
        Notify("Updating existing record with Source ID: " & Text(ThisRecord.ID), NotificationType.Information);
        Patch(
            Target_List,
            LookUp(Target_List, Title = Text(ThisRecord.ID)), // Find the existing record by Title
            {
                'Updated State': UpdatedState.Selected,
                'Updated City': UpdatedCity.Selected,
                'CUSTOMER ID': CustID.Text
            }
        ),
        // Create a new record if not found
Notify("Creating new record with Source ID: " & Text(ThisRecord.ID), NotificationType.Information);
		Patch(
            Target_List,
            Defaults(Target_List), // Create a new record
            {
                Title: Text(ThisRecord.ID),  // Map Source ID to Target Title
                'Updated State': UpdatedState.Selected,
                'Updated City': UpdatedCity.Selected,
                'CUSTOMER ID': CustID.Text
            }
        )
    );

    // Notify the end of processing for each record
    Notify("Finished processing record with Source ID: " & Text(ThisRecord.ID), NotificationType.Success, 3000);
);
 
Categories:
I have the same question (0)
  • Verified answer
    WarrenBelz Profile Picture
    155,257 Most Valuable Professional on at
    There are a few issues here that I will try and set out.
    • Firstly Notify functions inside a ForAll() statement are not a good idea, so I have removed them for the purpose of simplifying this.
    • The fundamental issue however is that you are referring to controls in the patch, but using (I assume) a collection in the ForAll(). You need to use the filtered Gallery if you are going to refer to control values.
    • Also I have simplified the new/update logic by finding the ID (I assume you are using SharePoint) of the target record. If it is present, the code will update that record. If not, it will create a new record.

    Notify(
       "Processing record,
       NotificationType.Information
    );
    ForAll(
       Filter(
          GalleryName.AllItems,
          YourCheckBox.Value
       ) As _Data,
       With(
          {
             _ID:
             LookUp(
                Target_List, 
                Title = Text(_Data.ID)
             ).ID
          },
          Patch(
             Target_List,
             {
                ID:_ID,
                'Updated State': _Data.UpdatedState.Selected,
                'Updated City': _Data.UpdatedCity.Selected,
                'CUSTOMER ID': _Data.CustID.Text
             }
          )
       )
    );
    Notify(
       "Finished processing record, 
       NotificationType.Success, 
    ​​​​​​​ 3000 );
     
    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 u
    seful in other ways, please consider giving it Thumbs Up.
    MVP (Business Applications)   Visit my blog Practical Power Apps

     
  • LB-08081540-0 Profile Picture
    12 on at
    Thanks for your response, this works as expected

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 1,070

#2
Valantis Profile Picture

Valantis 639

#3
11manish Profile Picture

11manish 608

Last 30 days Overall leaderboard