Extract Date from FileName in Copy Activity (ADF)

Ayush Chauhan 116 Reputation points
2021-05-29T13:35:11.883+00:00

We have multiple files with names as 'Amazon US Daily Sales Diagnostic_2021-05-10.xlsx', we want a solution to fetch this date from the filename and add a column by name 'date' in the table with this value through ADF by using copy activity.

Azure Storage Accounts
Azure Storage Accounts
Globally unique resources that provide access to data management services and serve as the parent namespace for the services.
2,669 questions
Azure Data Factory
Azure Data Factory
An Azure service for ingesting, preparing, and transforming data at scale.
9,483 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. PRADEEPCHEEKATLA-MSFT 76,586 Reputation points Microsoft Employee
    2021-06-01T07:22:21.397+00:00

    Hello anonymous user,

    Thanks for the question and using MS Q&A platform.

    You may follow the below steps to extract Date from FileName in Copy Activity (ADF):

    Step1: Use Get Metadata Activity to fetch Item name(file name) from dataset.

    101247-image.png

    Step2: Create a variable to hold Date value from file name.

    101236-image.png

    Step3: Use Set variable activity to set value for your variable (@split(split(activity('Get FileName').output.itemName,'_')1,'.')[0]).

    101333-image.png

    Step4: In Copy activity add additional column to add another column for this date on top of your source data.

    101343-image.png

    Hope this helps. Do let us know if you any further queries.

    ---------------------------------------------------------------------------

    Please "Accept the answer" if the information helped you. This will help us and others in the community as well.

    1 person found this answer helpful.

  2. PRADEEPCHEEKATLA-MSFT 76,586 Reputation points Microsoft Employee
    2021-06-02T06:33:06.357+00:00

    Hello anonymous user,

    Yes, you can use 'Childitems' instead of 'iteamName'.

    The below steps helps to extract Date from FileName in Copy Activity from a folder.

    Step1: Use Get Metadata Activity to fetch child Items from folder. Dataset should point to folder in which we have our files.

    101506-step1.png

    Step2: Create a variable to store date.

    101604-image.png

    Step3: Pass GetMetadata ouput childItems to ForEach Activity

    101605-image.png

    Step4: Inside ForEach, Use Set Varible activity to fetch date from Filename and store it in variable.

    101530-image.png

    Step5: Inside ForEach, Use Copy activity with Dataset Dynamically pointing to file and add additional column for the Date.

    101642-image.png

    ds_SalesExcel Data set details

    101612-image.png

    Hope this helps. Do let us know if you any further queries.

    ---------------------------------------------------------------------------

    Please "Accept the answer" if the information helped you. This will help us and others in the community as well.

    1 person found this answer helpful.