LAG and LEAD (Window Functions in ADF Data Flow):
- In ADF Data Flow, you can use the Window Transformation to replicate
LAG()
andLEAD()
functionality.
Set up the window transformation to partition by JobID
and order by CreateDate
.
Steps:
- Add a Window transformation in the data flow.
- In the partition, specify
JobID
. - In the sorting condition, specify
CreateDate
. - Create two new columns using window functions:
- For
LAG
(Previous status): Usefirst()
with an offset of 1 (this replicatesLAG()
). - For
LEAD
(if needed): Uselast()
with an offset of 1 to replicateLEAD()
.
- For
PreviousStatus = first(Status, 1)
PreviousSubStatus = first(SubStatus, 1)
RANK() Over Partition in ADF:
- The Window Transformation can also handle ranking by partitioning by
JobID
and ordering byCreateDate
.
Steps:
- Add another Window transformation.
- Partition by
JobID
. - Order by
CreateDate
. - Use the
rank()
function in ADF Data Flow to rank based on this partition.
Rank = rank()
- Partition by
Update for Status in Month:
- To replicate the final step in your SQL (
MERGE INTO FinalJobTable
), you can use the Join transformation.- You can apply the condition to filter only the rows with the rank
1
(i.e., the final row in the month). - After applying the filter, use an Alter Row transformation to mark the row for an update.
- You can apply the condition to filter only the rows with the rank
- Add a Filter transformation after ranking.
- Filter where
Rank = 1
. - Use an Alter Row transformation to update the
StatusInMonth
for these rows.
- Filter where