Dataflow String to Date Conversion

Luis Trujillo 20 Reputation points
2024-07-24T05:21:04.84+00:00

I have a dataflow with a derivate column activity, in this activity I create a new column based on another column using this expression:

iif(isDate(toString(i1), 'yyyyMMdd'),concat(substring(toString(i1), 1, 4),'/' ,substring(toString(i1), 5, 2),'/',substring(toString(i1), 7, 2)),'')

The goal is to format the string as yyyy/MM/dd if the input is a valid date otherwise return empty.

User's image

This works as expected but when using the output of this activity in a sink, I map this new column to a date type column in the sink, I get the warning that some columns have different data types, when doing data preview on the sink, the Date column is empty even that the derivate step has data for the column.

User's image

User's image

User's image

It seems that the sink cannot cast the string value to a date so it sets the column to NULL, what are my options? Any way to force the derivate column to be of type Date? I don't see any expression that would allow me to format a date and return it as a date.

Azure Data Factory
Azure Data Factory
An Azure service for ingesting, preparing, and transforming data at scale.
11,624 questions
0 comments No comments
{count} votes

Accepted answer
  1. Amira Bedhiafi 33,071 Reputation points Volunteer Moderator
    2024-07-24T13:23:05.75+00:00

    Try to use a derived column transformation instead :

    iif(
        isDate(toString(i1), 'yyyyMMdd'),
        toDate(concat(substring(toString(i1), 1, 4), '/', substring(toString(i1), 5, 2), '/', substring(toString(i1), 7, 2)), 'yyyy/MM/dd'),
        null()
    )
    

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.