If you're working with Power Automate Desktop (PAD) and dealing with lists, arrays, Excel rows, or files, then the For Each loop is one of your best buddies. In this article, I’ll walk you through how to use For Each action in PAD with a simple example and also share some best practices I’ve picked up from real-world usage.
The For Each loop allows you to repeat a set of actions for each item in a collection, like a list of numbers, rows from an Excel sheet, or even files in a folder.
📂 If you have 10 files in a folder and want to process each file, use For Each.
Name |
Department |
Gowtham |
ECE |
Ashok Raj |
CSE |
We want to display each name and department using PAD.
Step-by-step Flow
- Launch Power Automate Desktop
- Add “Launch Excel” action
- Uncheck “Visible” if you don’t want to open UI
![Launch excel]()
- Add “Open Workbook” action
- Set your Excel file path
![Excel file path]()
- Add “Read from Excel Worksheet”
- Output → %ExcelDataTable%
- Make sure “First line contains column names” is checked
![Read from excel worksheet]()
- Add “For Each” loop
- Value to iterate → %ExcelDataTable.Rows%
- Current item → %currentRow%
- Inside the loop, add Display Message:
- Title: Employee Info
- Message: → %currentRow%
![Display message]()
Output
You’ll get message boxes like:
![Get message boxes]()
And so on for each row.
✅ Best Practices for Using For Each in PAD
Here are some golden tips from my experience:
1. 🔒 Always check if the list/table is not empty
Before starting the loop, add a condition:
If %ExcelDataTable.Rows.Count% > 0
This prevents unnecessary errors.
2. 📌 Name your loop variables meaningfully
Instead of generic currentItem, rename it to currentRow, currentFile, or employee — helps in readability.
3. 🐞 Add error handling inside loops
Sometimes one item can fail, but others are fine. Add On Block Error inside the loop block if needed.
4. 🧹 Clean up resources
If using Excel, don’t forget to close the workbook and close Excel after the loop finishes.
5. ⏱ Avoid complex nested loops
If you can break it down into multiple flows or subflows, it becomes easier to maintain.
🙌 Summary
The For Each action in Power Automate Desktop is super powerful when used correctly. Whether you’re automating file operations, parsing Excel, or iterating over API responses — it's a must-have in your toolbox.
💡 With a few best practices and careful variable naming, you’ll make your flows easier to read, maintain, and scale.
💬 What’s Next?
Try looping through:
- Files in a folder using Get files in folder
- Rows from a CSV using Read text from file + Parse CSV
- Web API responses using Invoke Web Service + Parse JSON
If you liked this article or have any doubts, drop a comment below or ping me on C# Corner. Let’s automate together! 🔁✨
Until next time, happy automating!
✍️ Gowtham Rajamanickam
🏷️ Power Platform | Automate Everything