Skip to main content
Power Automate
    • Connectors
    • Templates
    • Take a guided tour
    • Digital process automation
    • Robotic process automation
    • Business process automation
    • Process advisor
    • AI Builder
  • Pricing
  • Partners
    • Blog
    • Documentation
    • Roadmap
    • Self-paced learning
    • Webinar
    • Business process and workflow automation topics
    • Overview
    • Issues
    • Give feedback
    • Overview
    • Forums
    • Galleries
    • Submit ideas
    • User groups
    • Register
    • ·
    • Sign in
    • ·
    • Help
    Go To
    • Microsoft Power Automate Community
    • Welcome to the Community!
    • News & Announcements
    • Get Help with Power Automate
    • General Power Automate Discussion
    • Using Connectors
    • Building Flows
    • Using Flows
    • Power Automate Desktop
    • Process Advisor
    • AI Builder
    • Power Automate Mobile App
    • Translation Quality Feedback
    • Connector Development
    • Power Platform Integration - Better Together!
    • Power Platform Integrations
    • Power Platform and Dynamics 365 Integrations
    • Galleries
    • Community Connections & How-To Videos
    • Webinars and Video Gallery
    • Power Automate Cookbook
    • Events
    • 2021 MSBizAppsSummit Gallery
    • 2020 MSBizAppsSummit Gallery
    • 2019 MSBizAppsSummit Gallery
    • Community Engagement
    • Community AMA
    • Community Blog
    • Power Automate Community Blog
    • Community Support
    • Community Accounts & Registration
    • Using the Community
    • Community Feedback
    cancel
    Turn on suggestions
    Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.
    Showing results for 
    Search instead for 
    Did you mean: 
    • Microsoft Power Automate Community
    • Galleries
    • Power Automate Cookbook
    • Re: Excel Batch Create, Update, and Upsert

    Re: Excel Batch Create, Update, and Upsert

    08-12-2022 05:46 AM

    Super User takolota
    Super User
    378 Views
    LinkedIn LinkedIn Facebook Facebook Twitter Twitter
    takolota
    Super User takolota
    Super User
    • Mark as New
    • Bookmark
    • Subscribe
    • Mute
    • Subscribe to RSS Feed
    • Permalink
    • Print
    • Report Inappropriate Content

    Excel Batch Create, Update, and Upsert

    ‎06-13-2022 09:31 AM

    Update & Create Excel Records 50-100x Faster

    I was able to develop an Office Script to update rows and an Office Scripts to create rows from Power Automate array data. So instead of a flow creating a new action API call for each individual row update or creation, this flow can just send an array of new data and the Office Scripts will match up primary key values, update each row it finds, then create the rows it doesn't find.
    And these Scripts do not require manually entering or changing any column names in the Script code.

     

    • In testing for batches of 1000 updates or creates, it's doing ~2500 row updates or creates per minute, 50x faster than the standard Excel create row or update row actions at max 50 concurrency. And it accomplished all the creates or updates with less than 25 actions or only 2.5% of the standard 1000 action API calls.

     

    • The Run Script code for processing data has 2 modes, the Mode 2 batch method that saves & updates a new instance of the table before posting batches of table ranges back to Excel & the Mode 1 row by row update calling on the Excel table.
    The Mode 2 script batch processing method will activate for creates & updates on tables less than 1 million cells. It does encounter more errors with larger tables because it is loading & working with the entire table in memory.
    Shoutout to Sudhi Ramamurthy for this great batch processing addition to the template!
    Code Write-Up: https://docs.microsoft.com/en-us/office/dev/scripts/resources/samples/write-large-dataset
    Video: https://youtu.be/BP9Kp0Ltj7U

    The Mode 1 script row by row method will activate for Excel tables with more than 1 million cells. But it is still limited by batch file size so updates & creates on larger tables will need to run with smaller cloud flow batch sizes of less than 1000 in a Do until loop. 
    The Mode 1 row by row method is also used when the ForceMode1Processing field is set to Yes.

     

    Office Script Code V5
    (Also included in a Compose action at the top of the template flow)

    Batch Update Script Code: https://drive.google.com/file/d/1kfzd2NX9nr9K8hBcxy60ipryAN4koStw/view?usp=sharing
    Batch Create Script Code: https://drive.google.com/file/d/13OeFdl7em8IkXsti45ZK9hqDGE420wE9/view?usp=sharing

    You can download the Version 5 of this template attached to this post, copy the Office Script codes into an online Excel instance, & try it out for yourself.
    -Open an online Excel workbook, go the the automate tab, select New Script, then copy & paste the Office Script code into the code editor. Do this for both the Batch Update and the Batch Create script code. You may want to name them BatchUpdateV5 & BatchCreateV5 appropriately.
    -Once you get the template flow into your environment, follow the notes in the flow to change the settings to your datasources, data, & office scripts.

     

    If you need just a batch update, then you can remove the batch create scope.
    If you need just a batch create, then you can replace the Run script Batch update rows action with the Run script Batch create rows action, delete the update script action, and remove the remaining batch create scope below it. Then any update data sent to the 1st Select GenerateUpdateData action will just be created, it won't check for rows to update.



    (ExcelBatchUpsertV5 is the core piece, ExcelBatchUpsertV5b includes a Do until loop set-up if you plan on updating and/or creating more than 1000 rows on large tables.)

     

    Anyone facing issues with the standard zip file import package method can check this post for an alternative method of importing the flow: https://powerusers.microsoft.com/t5/Power-Automate-Cookbook/Excel-Batch-Create-Update-and-Upsert/m-p... 


    Thanks for any feedback!

     

     

    watch?v=HiEU34Ix5gA

    ExcelBatchUpsertV5.2.zip
    ExcelBatchUpsertV5.2b.zip
    Labels:
    • Labels:
    • Button flows
    • Desktop flows
    • Scheduled flows
    Message 1 of 183
    26,156 Views
    17 Kudos
    Reply
    • All forum topics
    • Next Topic
    • « Previous
      • 1
      • 2
      • 3
      • 4
      • …
      • 19
    • Next »
    Anonymous
    Not applicable
    In response to takolota
    • Mark as New
    • Bookmark
    • Subscribe
    • Mute
    • Subscribe to RSS Feed
    • Permalink
    • Print
    • Report Inappropriate Content

    ‎07-21-2022 07:20 AM

    it matches and doesnt have any special characters do i put it as dynamic content or just the text?

    now i get: We were unable to run the script. Please try again.
    Runtime error: Line 14: Cannot read property 'join' of null
    clientRequestId: 0f5cb142-716e-4568-acb2-085a29d0754d

    Message 21 of 183
    457 Views
    0 Kudos
    Reply
    takolota
    Super User takolota
    Super User
    In response to Anonymous
    • Mark as New
    • Bookmark
    • Subscribe
    • Mute
    • Subscribe to RSS Feed
    • Permalink
    • Print
    • Report Inappropriate Content

    ‎07-21-2022 07:34 AM

    @Anonymous This is on the Batch Update, correct?

    Then this should be the specific line of JavaScript code that is erroring...

     

    let ArrayPK = table.getColumn(PrimaryKeyColumnName).getRange().getValues().join("#|#").split("#|#")

     

    When making this, I found that a join followed by a split helped get everything into a single level of an array, in other words it took an array of arrays and helped turn it into just a regular array.


    That join error is saying the primary key column array is returning null or it isn't finding any values in your primary key.

    Message 22 of 183
    451 Views
    0 Kudos
    Reply
    Anonymous
    Not applicable
    In response to takolota
    • Mark as New
    • Bookmark
    • Subscribe
    • Mute
    • Subscribe to RSS Feed
    • Permalink
    • Print
    • Report Inappropriate Content

    ‎07-21-2022 07:56 AM

    It is on the Batch Update, I have values in my table and they show up when i try to pivot table or power query so i dont know why its doing that

    Message 23 of 183
    445 Views
    0 Kudos
    Reply
    takolota
    Super User takolota
    Super User
    In response to Anonymous
    • Mark as New
    • Bookmark
    • Subscribe
    • Mute
    • Subscribe to RSS Feed
    • Permalink
    • Print
    • Report Inappropriate Content

    ‎07-21-2022 07:59 AM

    @Anonymous 

     

    You can try creating a new Script in Excel & just add the “table” variable initialization & run that above code within a console.log( ) to see what it returns.

    Message 24 of 183
    444 Views
    0 Kudos
    Reply
    vikrantv87
    vikrantv87
    Frequent Visitor
    • Mark as New
    • Bookmark
    • Subscribe
    • Mute
    • Subscribe to RSS Feed
    • Permalink
    • Print
    • Report Inappropriate Content

    ‎08-11-2022 01:20 PM

    Facing issue of invalid template at "Select reformat update data for script"....Please help !

     

    vikrantv87_1-1660249184129.png

     

     

    Message 25 of 183
    396 Views
    1 Kudo
    Reply
    takolota
    Super User takolota
    Super User
    In response to vikrantv87
    • Mark as New
    • Bookmark
    • Subscribe
    • Mute
    • Subscribe to RSS Feed
    • Permalink
    • Print
    • Report Inappropriate Content

    ‎08-11-2022 01:52 PM

    @vikrantv87 

     

    Could you please share some of the outputs from preceding actions.

    For example, what is the output for 

    Select Generate Update Data

    ReformatHeaderObject

    CheckInputs

    ??

    Message 26 of 183
    389 Views
    1 Kudo
    Reply
    vikrantv87
    vikrantv87
    Frequent Visitor
    In response to takolota
    • Mark as New
    • Bookmark
    • Subscribe
    • Mute
    • Subscribe to RSS Feed
    • Permalink
    • Print
    • Report Inappropriate Content

    ‎08-12-2022 05:42 AM

    All earlier steps are completed successfully. See below snapshots. just give you some background: 1) destination file already has data in the table. source data needs to be added below the existing data. 2) destination file has more columns than what I have mapped but i think that won't be an issue.

     

    is it necessary that primary key column should be the first one always ?

     

    vikrantv87_0-1660307642149.png

    vikrantv87_1-1660307700496.png

     

     

    Message 27 of 183
    379 Views
    0 Kudos
    Reply
    takolota
    Super User takolota
    Super User
    In response to vikrantv87
    • Mark as New
    • Bookmark
    • Subscribe
    • Mute
    • Subscribe to RSS Feed
    • Permalink
    • Print
    • Report Inappropriate Content

    ‎08-12-2022 05:46 AM

    @vikrantv87 

     

    No the primary key does not need to be the 1st column. That should all work fine.

    But I need you to click on the outputs of each of those actions so I can see what all the inputs are to the failing action.

    If it needs to open a separate window to view all the outputs, then you can save that output as a .txt file & share it here if your data isn’t sensitive.

    Message 28 of 183
    378 Views
    1 Kudo
    Reply
    vikrantv87
    vikrantv87
    Frequent Visitor
    • Mark as New
    • Bookmark
    • Subscribe
    • Mute
    • Subscribe to RSS Feed
    • Permalink
    • Print
    • Report Inappropriate Content

    ‎08-12-2022 05:51 AM

    @takolota 

    Data is sensitive can't share it here. do you think that PK in below is right ? or needs to be changed to something else.?

     

    vikrantv87_0-1660308623838.png

     

    Message 29 of 183
    376 Views
    0 Kudos
    Reply
    takolota
    Super User takolota
    Super User
    In response to vikrantv87
    • Mark as New
    • Bookmark
    • Subscribe
    • Mute
    • Subscribe to RSS Feed
    • Permalink
    • Print
    • Report Inappropriate Content

    ‎08-12-2022 05:55 AM

    @vikrantv87 

     

    That is the normal template. You shouldn’t need to edit this action.

    But I can’t really tell much beyond that, I don’t know what your primary key is from the previous action or if it matches the primary key in your source.

     

    If you can share more details of the flow run in a private message, please do.

    Message 30 of 183
    375 Views
    0 Kudos
    Reply
    • « Previous
      • 1
      • 2
      • 3
      • 4
      • …
      • 19
    • Next »

    Power Platform

    • Overview
    • Power BI
    • Power Apps
    • Power Pages
    • Power Automate
    • Power Virtual Agents

    • Sign up free
    • Sign in

    Browse

    • Templates
    • Connectors
    • Partners

    Downloads

    • Mobile
    • Gateway

    Learn

    • Documentation
    • Learn
    • Support
    • Community
    • Give feedback
    • Blog
    • Pricing

    • © 2023 Microsoft
    • Contact us
    • Trademarks
    • Privacy & cookies
    • Manage cookies
    • Terms of use
    • Terms & conditions
    California Consumer Privacy Act (CCPA) Opt-Out Icon Your California Privacy Choices