Trying to filter csv file based on content

Justin Doh 1,000 Reputation points
2026-07-22T21:45:14.68+00:00

I have an existing ADF pipeline that is creating an error due to some bad (or not acceptable data) displayed on the csv file.

Basically, instead of having proper header on the first row with certain amount columns (with data), csv file displays data like "There is no data to report." on the first row.

Originally, pipeline reads the file name by expression such as bottom inside Pipeline expression builder:

@concat('XXX_Check_DetailPalm Beach Corp' ,formatDateTime(addDays(utcNow(),  pipeline().globalParameters.DifferenceOfDate),'yyyyMMdd'),'*','.csv')

This expression is inside "Copy data".

This original pipeline was working fine until csv file with some weird data shows up that pipeline started failing.

I asked Microsoft Co-pilot to give me some architecture of this logic, and it suggested using first "Get Metadata" to grab "child items", and then use "ForEach" to read each csv files, and then inside "ForEach", I have second "Get Metadata" using a parameter and @item().name, and then, it goes to "If Condition" and "Copy data".

The error happens at "Copy data" (inside If Condition) that it still takes a csv file that has a bad data even though there is an expression that indicates to grab a csv file that has specific column names inside a csv file.

I would like to know the architecture of this type of logic first and possibly go into more details like Expression later.

Thank you so much!

Azure Data Factory
Azure Data Factory

An Azure service for ingesting, preparing, and transforming data at scale.


2 answers

Sort by: Most helpful
  1. Alex Burlachenko 25,120 Reputation points MVP Volunteer Moderator
    2026-07-23T09:07:08.07+00:00

    Justin Doh hi & thx for sharing urs issue here at Q&A portal,

    Get Metadata can list files and inspect properties such as name, size, or modification time, but it doesn’t validate CSV headers or inspect the file contents. That’s why the bad file still reaches Copy Activity.

    A better pipeline structure is

    Get Metadata (childItems) > Filter by filename > ForEach > Lookup first row > If Condition > Copy Data

    Inside the loop, use a parameterized CSV dataset pointing to @item().name. Configure the Lookup activity with firstRowOnly = true, but set First row as header to false. This makes ADF return the physical first line as values such as Prop_0, Prop_1, etc., rather than interpreting "There is no data to report." as a column name. Lookup supports returning only the first row of a delimited-text file.

    The If Condition can then check either for the rejection message

    @not(

    contains(

    string(activity('Lookup_First_Row').output.firstRow),
    
    'There is no data to report'
    

    )

    )

    Or, preferably, validate the expected header values explicitly:

    @and(

    equals(activity('Lookup_First_Row').output.firstRow.Prop_0, 'ExpectedColumn1'),

    equals(activity('Lookup_First_Row').output.firstRow.Prop_1, 'ExpectedColumn2'),

    equals(activity('Lookup_First_Row').output.firstRow.Prop_2, 'ExpectedColumn3')

    )

    Run Copy Data only through the True branch. In the False branch, move the file to a rejected folder, log its filename, or simply skip it.

    Keep the Copy Activity’s actual source dataset configured with First row as header = true. Use a separate dataset for the Lookup validation with First row as header = false. Otherwise ADF may interpret the bad message as a header before your condition can validate it.

    rgds,

    Alex

    &

    If my answer was helpful pls mark it and additional thx if u follow me at Q&A portal

    and at my blog https://ctrlaltdel.blog/

     

    Was this answer helpful?


  2. Pilladi Padma Sai Manisha 11,705 Reputation points Microsoft External Staff Moderator
    2026-07-22T22:53:26.01+00:00

    Hi @Justin Doh

    Thank you for reaching out Microsoft Q&A!.

    Based on your scenario, the overall pipeline design of using Get Metadata → ForEach → If Condition → Copy Data is a reasonable approach. However, the key limitation is that the Get Metadata activity can retrieve file-level metadata such as the file name, size, and last modified time, but it cannot inspect the contents of the CSV file. As a result, it cannot determine whether the first row contains the expected header or an unexpected message such as "There is no data to report."

    If the validation is currently being performed only using the file name or metadata, the pipeline will still attempt to process the invalid file, causing the Copy Data activity to fail.

    To validate the file contents before copying, you can use a Lookup activity to read the first row (or first line) of each CSV file and then use an If Condition activity to verify that it contains the expected header. If the validation succeeds, proceed with the Copy Data activity; otherwise, skip the file or move it to a separate location for further review.

    Please note that the Copy Data activity does not support filtering files based on their contents. If you need to validate or filter data within the file at scale, consider using a Mapping Data Flow, Azure Databricks, or another custom processing step before the copy operation.

    To better understand your scenario, could you please confirm the following?

    • Where are the CSV files stored (Azure Blob Storage or Azure Data Lake Storage Gen2)?
    • Is the invalid file always a single line containing "There is no data to report.", or are there other variations?
    • Are you using a DelimitedText dataset with First row as header enabled?

    With this information, we can suggest the most suitable validation approach for your pipeline.

    Was this answer helpful?

    0 comments No comments

Your answer

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