pythonCoder
pythonCoder

Reputation: 27

Get Max date value from append variable array - azure synapse pipeline

In my Synapse pipeline, I am looping through a set of filenames. Inside the loop, I use a "Get Metadata" activity to retrieve the last modified date of each file and append these dates to an array variable using the "Append Variable" activity. After the loop completes, I want to extract the maximum date value from the appended array and store it in a separate variable outside the loop.

enter image description here

outside the loop I have a set variable

enter image description here

Able to retrive the first value using the expression in set variable value as @variables('GetLatestFile')[1]

But not sure about how to get the max value from the values in array. For set variable activity I have the variable type as string.

Upvotes: 0

Views: 71

Answers (1)

Pratik Lad
Pratik Lad

Reputation: 8402

To compare Last modified dates and get max date from it you need to use the if activity as below:

  • First create RefDateTime variable in pipeline with ample value as 1900-01-01 00:00:00

enter image description here

  • Then add the If condition activity after get metadata activity where you are getting the last modified date for each file. and add the below expression:
@greaterOrEquals(ticks(activity('Get Metadata2').output.lastModified), ticks(variables('RefDateTime')))

enter image description here

it will check the incoming date for the file is greater than our reference date or not.

  • After this add set variable in true condition of if condition activity, if condtion meets it will update the RefDateTime variable.

enter image description here

Now you can take set variable activity outside forech activity and fetch the value of RefDateTime in it will return you max value from all the last modified dates.

enter image description here

Upvotes: 0

Related Questions