Power Automate  

Power Automate Desktop - How to Use For Each Loop and Best Practices (PAD)

👋 Hello developers!

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.

Let’s keep it hands-on and easy — the way we all like it!

🧠 What is a For Each Loop in Power Automate Desktop?

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.

In simple words

📂 If you have 10 files in a folder and want to process each file, use For Each.

🛠 Simple Example – Loop Through Excel Rows

Let’s say we have a local Excel file with employee data like this:

Name Department
Gowtham ECE
Ashok Raj CSE

We want to display each name and department using PAD.

Step-by-step Flow

  1. Launch Power Automate Desktop
  2. Add “Launch Excel” action
    • Uncheck “Visible” if you don’t want to open UI
      Launch excel
  3. Add “Open Workbook” action
    • Set your Excel file path
      Excel file path
  4. Add “Read from Excel Worksheet”
    • Output → %ExcelDataTable%
    • Make sure “First line contains column names” is checked
      Read from excel worksheet
  5. Add “For Each” loop
    • Value to iterate → %ExcelDataTable.Rows%
    • Current item → %currentRow%
  6. 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