how to loop increment of 30 days...

arkiboys 9,706 Reputation points
2024-01-17T08:49:01.78+00:00

I have two dates: @min_date as date @max_date as date In ADF, how can I loop through the above dates but in the increments of 30 days? for example start of loop: @min_date next: @min_date + 30 days --> something like dateadd(day, 30, @min_date) next 30 days next 30 days ... until it reaches @max_date Thank you

Azure Data Factory
Azure Data Factory
An Azure service for ingesting, preparing, and transforming data at scale.
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Amira Bedhiafi 41,111 Reputation points Volunteer Moderator
    2024-01-17T13:13:48.16+00:00

    Create two pipeline variables, say currentDate and maxDate, and assign your @min_date and @max_date to them respectively. The Until activity will loop until the currentDate is greater than or equal to maxDate. The expression for the until condition will be something like @greaterOrEquals(variables('currentDate'), variables('maxDate')). The set variable activity will be used to increment currentDate by 30 days. You can use an expression like @adddays(variables('currentDate'), 30) to set the currentDate variable. Inside the loop, you can add other activities that you want to perform for each incremented date.

    1 person found this answer helpful.

  2. Chakaravarthi Rangarajan Bhargavi 1,200 Reputation points MVP
    2024-01-17T12:34:57.3466667+00:00

    Hi arkiboys, Thank you for the question! Please check as below if it helps: In Azure Data Factory (ADF) expressions, you can achieve this by using a until activity along with expressions for date manipulation. Here's a sample expression for your scenario:

    @activity('YourUntilActivity').output < @max_date
    

    In the above expression, @activity('YourUntilActivity').output represents the current date in the loop. You would initialize this value with @min_date. Inside the loop, you can update the date using the expression:

    @addDays(activity('YourUntilActivity').output, 30)
    

    Make sure to set up an until activity with the mentioned condition and use this expression to update the date in each iteration. This will loop until the date is less than @max_date with increments of 30 days. Please look at the below reference for more understanding about the 'until' https://learn.microsoft.com/en-us/azure/data-factory/control-flow-until-activity Hope this answer helps you with solution! Please comment below if you need any assistance on the same. Happy to help! Best Regards, Chakravarthi Rangarajan Bhargavi -Please kindly accept the answer and vote 'Yes' if you feel helpful to support the community, thanks a lot.


Your answer

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