Home > Net >  Azure Data Factory-Data Flow, how to check if a column exists, if not add the column?
Azure Data Factory-Data Flow, how to check if a column exists, if not add the column?

Time:12-09

In the Azure Data Factory data mapping flow, is there a way to check if a column "Date" exists in the input file, if yes, select the "Date" column, if not create a "Date" column but leave the column blank in the output?

I tried with conditional select that if name=='Date', name the column as 'Date', but it the workflow fail if the "Date" column doesn't exist.

CodePudding user response:

You can use byName() in the derived column transformation.

This is my sample input data with Date column.

enter image description here

In derived column, use the below dataflow expression.

toDate(byName('Date'))

enter image description here

The above byName() will search for the given column name and if it is there in the columns list then it gives those values and if it not there it will give null values to the column.

Result when Date column present in source:

enter image description here

Source without Date column:

enter image description here

Result with Date column and values as NULL:

enter image description here

After derived column transformation, use select transformation to select your desired columns.

  • Related