azureazure-data-factoryazure-mapping-data-flow

Check if a Column Exists and Add it When Doesn't Exist


In the Azure Data Factory data mapping flow, is there a way to check if a column Date exists in the input file? If true, select the Date column, if not then 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 with the "Date" column doesn't exist.


Solution

  • 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.