[英]How to Perform for loop type of logic in Azure Data FLow
Here is my requirement:这是我的要求:
Basically in a for loop there are 3 things: initialisation, condition, loop基本上在 for 循环中有 3 件事:初始化、条件、循环
So i have to generate a row basing on for loop logic for every row like:所以我必须基于 for 循环逻辑为每一行生成一行,例如:
{Start_Rcvd Date}
(col in my table){Start_Rcvd Date}
(我表中的列)DateBetweenDRO
(New Column) <= {WIP AGE DATE}
(Col in my table)DateBetweenDRO
(新列) <= {WIP AGE DATE}
(我表中的列)addDays({DateBetweenDRO},1)
(Col in my table)addDays({DateBetweenDRO},1)
(我表中的 Col) Output: In the output, for every row it loops through the condition and generate a column and fills from initialsion value to loop ending condition. Output:在 output 中,对于每一行它循环条件并生成一列并从初始值填充到循环结束条件。
Let us consider 2 date cols NewDate: 31/01/2022 OldDate: 01/05/2022让我们考虑 2 个日期列 NewDate:31/01/2022 OldDate:01/05/2022
Now I am mentioning:现在我要提到:
initialization expression: NewDate(31/01/2022) conditional expression : NewDate<=OldDate loop : NewDate+1month初始化表达式:NewDate(31/01/2022) 条件表达式:NewDate<=OldDate循环:NewDate+1month
So For every row its generating 3 rows and adding 1 month every time as value in NewDate col.因此,对于每一行,它生成 3 行并每次添加 1 个月作为 NewDate col 中的值。
Can you help please how to achieve this kind of thing in Azure dataflow你能帮忙请问如何在Azure数据流中实现这种事情吗
How to Perform for loop type of logic in Azure Data FLow I tried to repro this scene in Azure data flow and below is the approach.
如何在 Azure 数据流中执行循环类型的逻辑我试图在 Azure 数据流中重现这个场景,下面是方法。
initialnewParameter="2022-01-05"
. initialnewParameter="2022-01-05"
中分配。 Source data is taken as in below image.源数据如下图所示。
In order to generate multiple rows, first total number of months between old date and new date is computed.为了生成多行,首先计算旧日期和新日期之间的总月数。
toInteger(round(monthsBetween(old_date,toDate($initialnewParameter)),0,1))
. toInteger(round(monthsBetween(old_date,toDate($initialnewParameter)),0,1))
。 This will give the rounded-up value of months between old and new date.这将给出旧日期和新日期之间月份的舍入值。
Maploop function is used to create an array starting from 1 to value of months between old and new date. Maploop function 用于创建一个数组,从 1 开始到新旧日期之间的月份值。
In derived column transformation column named monthsbw[] is created and expression is given as mapLoop(toInteger(round(monthsBetween(old_date,toDate($initialnewParameter)),0,1)),#index)
.在派生列转换列中创建名为monthsbw[]的表达式,表达式为
mapLoop(toInteger(round(monthsBetween(old_date,toDate($initialnewParameter)),0,1)),#index)
。
monthsbw[] is created and values are from 1 to months between old and new date as in below image. monthsbw[] 已创建,值介于旧日期和新日期之间的 1 到月之间,如下图所示。
Flatten transform is used and this data is unrolled by monthsbw array.使用Flatten 转换,此数据由monthsbw数组展开。
Output of the flattened data扁平数据的 Output
Derived column transformation is taken and monthbw is added to the dataflow parameter initialnewParameter
which stores the initial value of new date.进行派生列转换,并将 monthbw 添加到存储新日期初始值的数据流参数
initialnewParameter
中。 Expression for new_date column: addMonths(toDate($initialnewParameter),toInteger(monthbw)-1)
new_date 列的表达式:
addMonths(toDate($initialnewParameter),toInteger(monthbw)-1)
Output of the derived column activity: Output 的导出列活动:
By this way, you can generate multiple rows from a row in azure data flow.这样就可以将azure数据流中的一行生成多行。 You can use select transformation and select only required columns.
您可以使用 select 转换和 select 仅需要的列。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.