Adf set increment counter

Pankaj Joshi 391 Reputation points
2025-03-23T06:02:43.3066667+00:00

In ADF I am using ForEach activity(iterate 5000) which contains IF ELSE condition. When IF condition satisfied then I am performing task x. Now I need to set threshold counter (+1) , so that once threshold reach => 1000 and IF conditions satisfied then task x should get skipped. How can I achieve this in adf without using dataflow.

Azure Data Factory
Azure Data Factory
An Azure service for ingesting, preparing, and transforming data at scale.
11,639 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Vinodh247 34,666 Reputation points MVP Volunteer Moderator
    2025-03-23T10:45:03.6033333+00:00

    Hi ,

    Thanks for reaching out to Microsoft Q&A.

    What You Need to Do in ADF:

    1. Create a pipeline-level variable (counter) of type integer, initialized to 0.
    2. In your ForEach loop (iterating 5000 items), ensure it runs in sequential mode. This is critical to maintain variable state across iterations.
    3. Inside the loop:
      • First, apply your IF condition that decides whether Task X should run.
      • If the condition is true:
      • Add another IF block to check if the counter is still below your threshold (less than 1000).
      • If yes:
        • Execute Task X.
        • Increment the counter by 1 using a "Set Variable" activity.
      • If not:
        • Skip Task X.

    Key Reminders:

    Sequential execution is required to ensure counter increments reliably.

    Pipeline variables are the only way to manage state across iterations in ADF (without Data Flows).

    Avoid complex expressions; keep it modular with nested activities for clarity.

    Please feel free to click the 'Upvote' (Thumbs-up) button and 'Accept as Answer'. This helps the community by allowing others with similar queries to easily find the solution.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.