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.


1 answer

Sort by: Most helpful
  1. Alex Burlachenko 25,115 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?


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.