Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Join us at FabCon Vienna from September 15-18, 2025, for the ultimate Fabric, Power BI, SQL, and AI community-led learning event. Save €200 with code FABCOMM. Get registered

Reply
Anonymous
Not applicable

Pipeline ForEach Activity parallel execution interferes with Set Variable

Hello everyone!

 

I have a pipeline like this:
Screenshot 2024-07-03 161138.png

 

If I set the ForEach activity to sequential execution, everything works fine.

Screenshot 2024-07-03 161152.png

 

However, if I set it to parallel, the variable gets set twice first and then the copy activity is executed twice for the last set variable value (I know this isn't visible in the picture, I just want to illustrate it).

Screenshot 2024-07-03 161640.png

 

This is not what I understand as parallelism; this is sequentialism with a surprise order of operations. Is this happening to anyone else? What is going on? Can I ameliorate it? Thanks for your input!

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @Anonymous ,

When running in parallel, variables can indeed behave unpredictably because they are not thread-safe. This can lead to the kind of unexpected behavior you’re seeing, where the variable gets set multiple times before the copy activity executes.

 

Since variables are not thread-safe, try to avoid using them within parallel loops. Instead, consider using parameters or passing values directly to activities.

 

If possible, stick with sequential execution for activities that depend on variable values. This ensures that each iteration completes before the next one starts, maintaining the correct order of operations.

Also I think you can look at this document: Running a ForEach activity in parallel mode - Microsoft Q&A

 

 

 

Best Regards

Yilong Zhou

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

3 REPLIES 3
tmjones2
Helper I
Helper I

It would be really neat if they could give us a warning when you set a variable inside of a parallel for each. But since they don't, we all get to waste an hour trying to figure out what is going on for ourselves.

Cool.

Anonymous
Not applicable

By the way, how I solved this now is to not even work with a variable. I directly use the ForEach item and subselect the column I want like this: @item().column_name

Anonymous
Not applicable

Hi @Anonymous ,

When running in parallel, variables can indeed behave unpredictably because they are not thread-safe. This can lead to the kind of unexpected behavior you’re seeing, where the variable gets set multiple times before the copy activity executes.

 

Since variables are not thread-safe, try to avoid using them within parallel loops. Instead, consider using parameters or passing values directly to activities.

 

If possible, stick with sequential execution for activities that depend on variable values. This ensures that each iteration completes before the next one starts, maintaining the correct order of operations.

Also I think you can look at this document: Running a ForEach activity in parallel mode - Microsoft Q&A

 

 

 

Best Regards

Yilong Zhou

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Helpful resources

Announcements
May FBC25 Carousel

Fabric Monthly Update - May 2025

Check out the May 2025 Fabric update to learn about new features.

June 2025 community update carousel

Fabric Community Update - June 2025

Find out what's new and trending in the Fabric community.

Top Solution Authors