Hello everybody,
I'm fairly new with Microsoft Power Automate. I want to apply this office script to multiples Excel sheets in my Onedrive folder. This is the flow that I create, not sure why but it takes HOURS to run/test and I ended up canceling all of them because it took too long. I have a slight idea that it might be because of my license (I don't really understand about what licenses out there that allow me to run my script in about 30 Excel sheets). I have Microsoft 365 Business plan but Power Automate plan free.
Do I really have to upgrade my license to have flow run faster? Is there anyway I can improve this? For example replace "Apply to each" by another function? Thank you!
Hi @Kuromi102 - sorry to hear that you're running into performance issues! While Power Automate licensing does affect certain limits such as the number of requests you can make, I don't think it should affect performance. There might be room to optimize your scripts so they run faster. Would you be able to share your script code?
Thank you for your response! This is the Office Script code that I wrote.
function main(workbook: ExcelScript.Workbook) {
let selectedSheet = workbook.getActiveWorksheet();
// Auto fit the columns of all cells on selectedSheet
selectedSheet.getRange().getFormat().autofitColumns();
// Delete range E:F on selectedSheet
selectedSheet.getRange("E:F").delete(ExcelScript.DeleteShiftDirection.left);
// Insert at range B:B on selectedSheet, move existing cells right
selectedSheet.getRange("B:B").insert(ExcelScript.InsertShiftDirection.right);
// Set range B1 on selectedSheet
selectedSheet.getRange("B1").setValue("Undeliverable Date");
// Insert at range D:D on selectedSheet, move existing cells right
selectedSheet.getRange("D:D").insert(ExcelScript.InsertShiftDirection.right);
// Insert at range D:D on selectedSheet, move existing cells right
selectedSheet.getRange("D:D").insert(ExcelScript.InsertShiftDirection.right);
selectedSheet.getRange("D:D").insert(ExcelScript.InsertShiftDirection.right);
// Text to columns on range C1:C33 on selectedSheet
let lastRow = (selectedSheet.getUsedRange().getLastRow().getRowIndex() + 1).toString();
for (let row = 0; row < selectedSheet.getRange("C1:C" + lastRow).getRowCount() ; row++) {
let sourceRange = selectedSheet.getRange("C1:C" + lastRow);
let destinationRange = selectedSheet.getRange("D1");
let sourceRangeValuesArray = sourceRange.getRow(row).getValues()[0][0].toString().split(/[\t ]/)
let sourceRangeValues = [sourceRangeValuesArray[0], sourceRangeValuesArray[1], sourceRangeValuesArray.slice(2,sourceRangeValuesArray.length).join(" ")];
destinationRange.getOffsetRange(row, 0).getResizedRange(0, sourceRangeValues.length - 1).setValues([sourceRangeValues]);
}
// Set range C1:F1 on selectedSheet
selectedSheet.getRange("C1:F1").setValues([["Full Name","First Name","Middle Name","Last Name"]]);
// Text to columns on range K1:K33 on selectedSheet
for (let row = 0; row < selectedSheet.getRange("K1:K" + lastRow).getRowCount() ; row++) {
let sourceRange = selectedSheet.getRange("K1:K" + lastRow);
let destinationRange = selectedSheet.getRange("L1");
let sourceRangeValues = sourceRange.getRow(row).getValues()[0][0].toString().split(/[\t,]/)
destinationRange.getOffsetRange(row, 0).getResizedRange(0, sourceRangeValues.length - 1).setValues([sourceRangeValues]);
}
// Text to columns on range H1:H76 on selectedSheet
for (let row = 0; row < selectedSheet.getRange("H1:H" + lastRow).getRowCount(); row++) {
let sourceRange = selectedSheet.getRange("H1:H" + lastRow);
let destinationRange = selectedSheet.getRange("H1");
let sourceRangeValues = sourceRange.getRow(row).getValues()[0][0].toString().split(/[\t,]/)
destinationRange.getOffsetRange(row, 0).getResizedRange(0, sourceRangeValues.length - 1).setValues([sourceRangeValues]);
}
// Set range K1 on selectedSheet
selectedSheet.getRange("K1").setValue("Country");
}
Try the following script:
function main(workbook: ExcelScript.Workbook) {
let selectedSheet = workbook.getActiveWorksheet();
// Delete range E:F on selectedSheet
selectedSheet.getRange("E:F").delete(ExcelScript.DeleteShiftDirection.left);
// Auto fit the columns of all cells on selectedSheet
selectedSheet.getRange().getFormat().autofitColumns();
// Insert at range B:B on selectedSheet, move existing cells right
selectedSheet.getRange("B:B").insert(ExcelScript.InsertShiftDirection.right);
// Set range B1 on selectedSheet
selectedSheet.getRange("B1").setValue("Undeliverable Date");
// Insert at range D:D on selectedSheet, move existing cells right
let columnToInsert = selectedSheet.getRange("D:D");
columnToInsert.insert(ExcelScript.InsertShiftDirection.right);
columnToInsert.insert(ExcelScript.InsertShiftDirection.right);
columnToInsert.insert(ExcelScript.InsertShiftDirection.right);
// Text to columns on range C1:C33 on selectedSheet
let lastRow = (selectedSheet.getUsedRange().getLastRow().getRowIndex() + 1).toString();
let sourceRange = selectedSheet.getRange("C1:C" + lastRow);
let sourceRangeRowCount = sourceRange.getRowCount();
let destinationRange = selectedSheet.getRange("D1");
for (let row = 0; row < sourceRangeRowCount; row++) {
let sourceRangeValuesArray = sourceRange.getRow(row).getValues()[0][0].toString().split(/[\t ]/)
let sourceRangeValues = [sourceRangeValuesArray[0], sourceRangeValuesArray[1], sourceRangeValuesArray.slice(2, sourceRangeValuesArray.length).join(" ")];
destinationRange.getOffsetRange(row, 0).getResizedRange(0, sourceRangeValues.length - 1).setValues([sourceRangeValues]);
}
// Set range C1:F1 on selectedSheet
selectedSheet.getRange("C1:F1").setValues([["Full Name", "First Name", "Middle Name", "Last Name"]]);
// Text to columns on range K1:K33 on selectedSheet
sourceRange = selectedSheet.getRange("K1:K" + lastRow);
sourceRangeRowCount = sourceRange.getRowCount();
destinationRange = selectedSheet.getRange("L1");
for (let row = 0; row < sourceRangeRowCount; row++) {
let sourceRangeValues = sourceRange.getRow(row).getValues()[0][0].toString().split(/[\t,]/)
destinationRange.getOffsetRange(row, 0).getResizedRange(0, sourceRangeValues.length - 1).setValues([sourceRangeValues]);
}
// Text to columns on range H1:H76 on selectedSheet
sourceRange = selectedSheet.getRange("H1:H" + lastRow);
sourceRangeRowCount = sourceRange.getRowCount();
destinationRange = selectedSheet.getRange("H1");
for (let row = 0; row < sourceRangeRowCount; row++) {
let sourceRangeValues = sourceRange.getRow(row).getValues()[0][0].toString().split(/[\t,]/)
destinationRange.getOffsetRange(row, 0).getResizedRange(0, sourceRangeValues.length - 1).setValues([sourceRangeValues]);
}
// Set range K1 on selectedSheet
selectedSheet.getRange("K1").setValue("Country");
}
The main thing I tried to do was reduce the number of calls to getRange. For example, in your original script, you define sourceRange and destinationRange within your for loops, but those variables don't actually change over the course of the loop, so moving those definitions outside should improve performance.
Let me know if that helps, or if you have any questions!
One thing I forgot: when running a script through Power Automate, it's best to avoid using getActiveWorksheet since it's not always clear which worksheet is "active" if the flow runs while Excel isn't open. Instead, you should get a specific worksheet by name (potentially passing in the worksheet name as a parameter).
Thank you very much for your help! I really appreciate your fixed script! It looks really clean now!!
However, I've tried with the flow but unfortunately it doesn't improve the consumed time. It has been an hour but still running. I wonder if there is any other way to fix this issue?
Could you share a screenshot of an execution from the flow's run history? I'm wondering whether the script ever runs successfully, or if the flow is just taking a long time because there are a lot of files to run the script on.
Thank you and sure, I can share!
This is the flow run history. As you see, I canceled all the time because it took too long. The "test failed" and "failed" status were when I tried to make the Concurrency Control on with 20 degree of parallelism. Please let me know if you had any idea or solution! thank you very much!
Could you select a specific run (from the timestamp) and share a screenshot of that? That should show which actions were executed and how long each one took.
Yes, so it looks like it always stuck at "Apply to each". That's why I wonder if there is any better solution to replace "Apply to each" function.
Can you expand "apply to each" to see how many times the script runs?
Unfortunately, I don't think there's a way to avoid using apply to each because a script can only run on a single workbook at a time.
I'm not sure why but "apply to each" can't be expanded from my end. I tried to click multiple times but it just doesn't expand. 😞
That's strange... Is there any error? Can you expand "list files in folder" and share the full output of that action (sensitive data removed as needed)?
For some reasons my replies disappeared even if I tried to repost. But this is the expanded "list files in folder". I appreciate your help!
That output seems correct. Could you try to test the following?
I'm hoping that can help us narrow down the issue.
Dear Community Members, We'd like to let you know of an upcoming change to the community platform: starting July 16th, the platform will transition to a READ ONLY mode until July 22nd. During this period, members will not be able to Kudo, Comment, or Reply to any posts. On July 22nd, please be on the lookout for a message sent to the email address registered on your community profile. This email is crucial as it will contain your unique code and link to register for the new platform encompassing all of the communities. What to Expect in the New Community: A more unified experience where all products, including Power Apps, Power Automate, Copilot Studio, and Power Pages, will be accessible from one community.Community Blogs that you can syndicate and link to for automatic updates. We appreciate your understanding and cooperation during this transition. Stay tuned for the exciting new features and a seamless community experience ahead!
We are excited to announce the Summer of Solutions Challenge! This challenge is kicking off on Monday, June 17th and will run for (4) weeks. The challenge is open to all Power Platform (Power Apps, Power Automate, Copilot Studio & Power Pages) community members. We invite you to participate in a quest to provide solutions to as many questions as you can. Answers can be provided in all the communities. Entry Period: This Challenge will consist of four weekly Entry Periods as follows (each an “Entry Period”) - 12:00 a.m. PT on June 17, 2024 – 11:59 p.m. PT on June 23, 2024 - 12:00 a.m. PT on June 24, 2024 – 11:59 p.m. PT on June 30, 2024 - 12:00 a.m. PT on July 1, 2024 – 11:59 p.m. PT on July 7, 2024 - 12:00 a.m. PT on July 8, 2024 – 11:59 p.m. PT on July 14, 2024 Entries will be eligible for the Entry Period in which they are received and will not carryover to subsequent weekly entry periods. You must enter into each weekly Entry Period separately. How to Enter: We invite you to participate in a quest to provide "Accepted Solutions" to as many questions as you can. Answers can be provided in all the communities. Users must provide a solution which can be an “Accepted Solution” in the Forums in all of the communities and there are no limits to the number of “Accepted Solutions” that a member can provide for entries in this challenge, but each entry must be substantially unique and different. Winner Selection and Prizes: At the end of each week, we will list the top ten (10) Community users which will consist of: 5 Community Members & 5 Super Users and they will advance to the final drawing. We will post each week in the News & Announcements the top 10 Solution providers. At the end of the challenge, we will add all of the top 10 weekly names and enter them into a random drawing. Then we will randomly select ten (10) winners (5 Community Members & 5 Super Users) from among all eligible entrants received across all weekly Entry Periods to receive the prize listed below. If a winner declines, we will draw again at random for the next winner. A user will only be able to win once overall. If they are drawn multiple times, another user will be drawn at random. Individuals will be contacted before the announcement with the opportunity to claim or deny the prize. Once all of the winners have been notified, we will post in the News & Announcements of each community with the list of winners. Each winner will receive one (1) Pass to the Power Platform Conference in Las Vegas, Sep. 18-20, 2024 ($1800 value). NOTE: Prize is for conference attendance only and any other costs such as airfare, lodging, transportation, and food are the sole responsibility of the winner. Tickets are not transferable to any other party or to next year’s event. ** PLEASE SEE THE ATTACHED RULES for this CHALLENGE** Week 1 Results: Congratulations to the Week 1 qualifiers, you are being entered in the random drawing that will take place at the end of the challenge. Community MembersNumber SolutionsSuper UsersNumber Solutions Deenuji 9 @NathanAlvares24 17 @Anil_g 7 @ManishSolanki 13 @eetuRobo 5 @David_MA 10 @VishnuReddy1997 5 @SpongYe 9JhonatanOB19932 (tie) @Nived_Nambiar 8 @maltie 2 (tie) @PA-Noob 2 (tie) @LukeMcG 2 (tie) @tgut03 2 (tie) Week 2 Results: Congratulations to the Week 2 qualifiers, you are being entered in the random drawing that will take place at the end of the challenge. Week 2: Community MembersSolutionsSuper UsersSolutionsPower Automate @Deenuji 12@ManishSolanki 19 @Anil_g 10 @NathanAlvares24 17 @VishnuReddy1997 6 @Expiscornovus 10 @Tjan 5 @Nived_Nambiar 10 @eetuRobo 3 @SudeepGhatakNZ 8 Week 3 Results: Congratulations to the Week 3 qualifiers, you are being entered in the random drawing that will take place at the end of the challenge. Week 3:Community MembersSolutionsSuper UsersSolutionsPower Automate Deenuji32ManishSolanki55VishnuReddy199724NathanAlvares2444Anil_g22SudeepGhatakNZ40eetuRobo18Nived_Nambiar28Tjan8David_MA22 Week 4 Results: Congratulations to the Week 4 qualifiers, you are being entered in the random drawing that will take place at the end of the challenge. Week 4:Community MembersSolutionsSuper UsersSolutionsPower Automate Deenuji11FLMike31Sayan11ManishSolanki16VishnuReddy199710creativeopinion14Akshansh-Sharma3SudeepGhatakNZ7claudiovc2CFernandes5 misc2Nived_Nambiar5 Usernametwice232rzaneti5 eetuRobo2 Anil_g2 SharonS2
On July 16, 2024, we published the 2024 release wave 2 plans for Microsoft Dynamics 365 and Microsoft Power Platform. These plans are a compilation of the new capabilities planned to be released between October 2024 to March 2025. This release introduces a wealth of new features designed to enhance customer understanding and improve overall user experience, showcasing our dedication to driving digital transformation for our customers and partners. The upcoming wave is centered around utilizing advanced AI and Microsoft Copilot technologies to enhance user productivity and streamline operations across diverse business applications. These enhancements include intelligent automation, AI-powered insights, and immersive user experiences that are designed to break down barriers between data, insights, and individuals. Watch a summary of the release highlights. Discover the latest features that empower organizations to operate more efficiently and adaptively. From AI-driven sales insights and customer service enhancements to predictive analytics in supply chain management and autonomous financial processes, the new capabilities enable businesses to proactively address challenges and capitalize on opportunities.
We're embarking on a journey to enhance your experience by transitioning to a new community platform. Our team has been diligently working to create a fresh community site, leveraging the very Dynamics 365 and Power Platform tools our community advocates for. We started this journey with transitioning Copilot Studio forums and blogs in June. The move marks the beginning of a new chapter, and we're eager for you to be a part of it. The rest of the Power Platform product sites will be moving over this summer. Stay tuned for more updates as we get closer to the launch. We can't wait to welcome you to our new community space, designed with you in mind. Let's connect, learn, and grow together. Here's to new beginnings and endless possibilities! If you have any questions, observations or concerns throughout this process please go to https://aka.ms/PPCommSupport. To stay up to date on the latest details of this migration and other important Community updates subscribe to our News and Announcements forums: Copilot Studio, Power Apps, Power Automate, Power Pages