(+351) 21 24 10006  ·  info@bconcepts.pt
Carnaxide, Lisbon

How to use the ForEach activity in Azure Data Factory

João Barros 07 de July de 2026 4 min read

The ForEach activity in Azure Data Factory lets you repeat a set of actions for each element in a list, without duplicating activities in your pipeline. Instead of creating the same activity dozens of times, you define the action once and ForEach handles the repetition. It is the ideal approach for processing several files, tables, or parameters at once. Below you will use the ForEach activity in Azure Data Factory to loop through a list of tables and run an action for each one.

Prerequisites

  • An Azure Data Factory instance (you can create one in the Azure portal).
  • Access to ADF Studio to create and edit pipelines.
  • Basic knowledge of pipelines, activities, and parameters in ADF.
  • Optional: a linked service and a dataset, if you want to copy real data inside the loop.

Step 1: Create the pipeline and a list parameter

In ADF Studio, open the Author tab and create a new pipeline. Go to the Parameters tab and add a parameter of type Array named tableList. Storing the list in a parameter makes the pipeline reusable: you can change the values without touching the logic. Set a default value so you can test right away:

["Clientes", "Produtos", "Vendas"]

Step 2: Add the ForEach activity

In the activities pane, open the Iteration & conditionals group and drag the ForEach activity onto the canvas. With it selected, go to the Settings tab. In the Items field you point to the list to iterate over using an expression (expressions in ADF always start with @):

@pipeline().parameters.tableList

By default, ForEach runs iterations in parallel (up to 20 at a time), which is fast but can overload the source or the sink. If order matters, enable the Sequential option so the iterations run one at a time.

Step 3: Define the actions inside the loop

Click the pencil icon inside the ForEach activity to open the inner canvas. This is where you place the activities that repeat on each iteration — for example a Copy, a Stored Procedure, or, just for testing, a Set Variable activity. To refer to the current element of the list, use the @item() function:

@item()

That value can go into other expressions. For example, to dynamically build a query that counts the rows of the current table:

@concat('SELECT COUNT(1) FROM ', item())

If the list held objects instead of plain text, you would access each property with @item().propertyName. Inside the loop you can also chain several activities, just as you would in a normal pipeline.

Step 4: Control parallelism

Still in the Settings tab, the Batch count field defines how many iterations run at the same time (between 1 and 50) when the mode is not sequential. Lower this value if you see throttling errors on the database or target service; raise it when you want more speed and the source can handle the load.

Tip: start with a low Batch count in production and increase it gradually while you watch performance.

Verify the result

Click Debug to run the pipeline. In the Output pane, the ForEach activity expands into one iteration per element in the list — in this example, three iterations: Clientes, Produtos, and Vendas. Confirm that they all finish with a green check and that the number of iterations matches the size of the list. If one fails, open that iteration and check the @item() expression and the inner activity.

Conclusion

You can now use ForEach to iterate over any list: file names from a Get Metadata activity, tables returned by a Lookup, or values passed as a parameter at run time. A very common pattern is to combine Lookup (to read a control table) with ForEach (to process each row), building metadata-driven pipelines. The next step is to try that pattern with real data. Which list will you loop through first — tables, files, or APIs?