How to Increment a Variable in ADF (Azure Data Factory)

If you have come to this page then you must have discovered by now that Azure Data Factory doesn’t allow you to assign a new value to the same variable in an expression i.e. self assignment is not possible inside the expression. This becomes relevant when you are implementing the loops and want to increment the variable within each iteration.

The workaround to achieve the same is to use two set of variables i.e. first increment a temporary variable and then assign this temporary variable to main variable keeping track of each iteration. Let’s see how we implemented this in a pipeline –

We created two variables – TempCounter as a temporary variable and then Counter, the main variable. Then, inside the Until loop, we used two set variable activities –

Since the variable is of string type so first this needs to be converted into integer and then need to be converted back to string.

Even Microsoft is well aware of this limitation and have itself documented this in their official ADF docs.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s