How to extract the current file name from azure data factory and store the value in a dataset for use

LI CHENG LAM 25 Reputation points
2023-06-02T02:15:02.37+00:00

I have a dataset which name as TMK_20230105_010112.csv and being use as the source file in data flow, I would like to extract the file name (TMK_20220105_010112) out and put it back to the source file as a additional column - Filename.

Azure Data Factory
Azure Data Factory
An Azure service for ingesting, preparing, and transforming data at scale.
9,516 questions
{count} vote

Accepted answer
  1. QuantumCache 20,031 Reputation points
    2023-06-02T16:25:44.52+00:00

    Hello @adf001 Thanks for posting this question on this forum!

    The ADF Pipeline Looks like below :

    First create Pipeline Variable called "FileName"

    GetMetadata-->SetVariable-->CopyData

    User's image

    GetMetadata: Stage

    Remember to output Field List: Item Name

    User's image

    Set Variable: capture the Source FileName

    @activity('Get Metadata Of File').output.itemName
    

    User's image

    Copy Data Activity:

    Source: --> Add New Column--> Put the name as -->"FileName" and the Custom value as --> @variables('FileName')

    User's image

    Pro Tip: Source--> Click Preview Data --> Provide the Variable Name for the FileName as for testing purpose ... example: Salesheader in my example!

    User's image

    And you will see the Preview of Data with the Newly Added Column "FileName", this is just a quick testing to see the source data is enhanced or not?

    User's image

    Sink: Is as normal , no fancy settings, so I am skipping the image!

    Mapping: We see the 'Import Schema' has done the mapping along with the Additional Column Name called "FileName".

    User's image

    Output: Run the ADF pipeline and see the output file having the additional column !!!!

    We now see the Output file has a new Column added for the FileName!!!!

    User's image

    1 person found this answer helpful.
    0 comments No comments

1 additional answer

Sort by: Most helpful
  1. Joseph G 5 Reputation points
    2024-03-28T19:53:31.7866667+00:00

    Wow... this is extremely helpful. Very well explained and laid out!

    1 person found this answer helpful.