Hi ,
Thanks for reaching out to Microsoft Q&A.
What You Need to Do in ADF:
- Create a pipeline-level variable (
counter
) of type integer, initialized to 0. - In your ForEach loop (iterating 5000 items), ensure it runs in sequential mode. This is critical to maintain variable state across iterations.
- 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.