To dynamically reference column names in a Derived Column transformation in Azure Data Factory (ADF) Dataflow, you can use a combination of parameters and expressions. Here's a step-by-step approach to achieve this:
- Create a pipeline parameter that holds the list of column names. For example,
UpdateColumns
containing'column1_cnt,column2_cnt,column3_cnt'
. - Use the
split
function to convert the comma-separated string into an array of column names. - Use a
ForEach
activity to iterate over the array of column names. - Within the Derived Column transformation, use the
byName
function to dynamically reference column names.
Here's an example of how you can set this up:
Pipeline Parameter:
{
"name": "UpdateColumns",
"type": "String",
"defaultValue": "column1_cnt,column2_cnt,column3_cnt"
}
Split the Parameter:
@split(pipeline().parameters.UpdateColumns, ',')
ForEach Activity:
- Add a
ForEach
activity to iterate over the array of column names. - Inside the
ForEach
activity, add a Data Flow activity.
Derived Column Transformation:
- In the Data Flow, add a Derived Column transformation.
- Use the following expression to dynamically reference the column names:ple Expression
iif(isNull(byName($$)), toLong(byName(replace($$, '_cnt', '_cnt_avg'))), toLong(byName($$)))
Assuming you have a column name currentColumn
in the ForEach
activity, the expression in the Derived Column transformation would look like this:
iif(isNull(byName(currentColumn)), toLong(byName(replace(currentColumn, '_cnt', '_cnt_avg'))), toLong(byName(currentColumn)))
This approach allows you to dynamically reference and transform column names without hard-coding them, making your solution more flexible and maintainable
Hope this helps. Do let us know if you any further queries.