How to Remove Apply to Each in Power Automate Excel Flows
Question details
The user wants to prevent Power Automate from automatically wrapping Excel Office Script actions in an Apply to each loop.

- Product
- Power Automate & Microsoft Excel
- Device & OS
- not provided
- Scenario
- Running an automated flow to convert CSV to Excel or process data using Office Scripts.
- Observed behavior
- Power Automate automatically adds an Apply to each loop when receiving an array from file actions, causing the flow to slow down, time out, or throw Excel connection errors.
Confirm whether your workflow is intended to process multiple files or just a single specific file. If only one file is expected, you can safely bypass the automatic loop by using exact identifiers.
Use Single File Identifier Instead of Dynamic Array
Prevent Power Automate from triggering the loop by providing an exact file identifier or using expressions to extract a single item from the array.
Power Automate automatically creates an 'Apply to each' loop whenever it detects that an input is formatted as an array (a list of items), even if that list only contains one item. By manually specifying that you only want the first item, you can break the loop.
Drag your 'Run script' (Office Scripts) action outside of the 'Apply to each' block, then delete the 'Apply to each' block entirely.
Instead of selecting the default dynamic array (like 'value' from a 'List files in folder' action), click 'See more' to find specific file properties.
If you must use the output of an array action, click on the input field, switch to the 'Expression' tab, and use the first() function. For example: first(outputs('List_files_in_folder')?['body/value'])?['Id'] to isolate a single file without triggering a loop.

Configure the Preceding Action to Return One Item
Limit the results of your file-fetching action so that it only passes a single file to your Excel Office Script action.
Verify Excel Online Permissions and Concurrency
If connection errors persist after removing the loop, the issue may be related to file locks, permissions, or flow concurrency limits.
Process Spreadsheets Faster with WPS Office
Struggling with complex Power Automate workflows, execution timeouts, and Office Script connection errors? Try WPS Office. It provides a lightweight, highly compatible, and user-friendly spreadsheet environment for all your data processing tasks without the heavy cloud infrastructure limitations.
- 1. Download the software: Visit the official WPS website and download the free WPS Office suite.
- 2. Install WPS Office: Run the installer and follow the quick on-screen instructions.
- 3. Open your files: Open your CSV or Excel files directly in WPS Spreadsheets to edit and process your data effortlessly.

Frequently Asked Questions
Why does Power Automate automatically add an Apply to each loop?
Power Automate automatically adds this loop whenever you map dynamic content that comes from an array (a list of items). Even if your folder only contains one file, the 'List files' action outputs an array, prompting the system to loop through the results.
How do I fix Excel Office Script timeout errors in Power Automate?
Timeout errors often occur because the script is inside an 'Apply to each' loop running across multiple files simultaneously. Removing the loop using the first() expression or setting the loop's concurrency control to 1 will resolve most timeout issues.
Can I convert CSV to Excel without using Office Scripts?
Yes. While Office Scripts are commonly used in Power Automate for this task, you can also use third-party connectors or premium actions like 'Create table' in Excel Online to handle basic CSV data mapping without writing custom TypeScript.
What is the first() expression in Power Automate?
The first() expression is a formula used to extract only the very first item from an array. Using this on a file list output allows you to pass a single file identifier to subsequent actions, completely bypassing the need for an Apply to each loop.




