How to write expression to get the output of 2nd row on certain column in csv file?

Justin Doh 860 Reputation points
2023-08-10T23:31:44.5666667+00:00

I am trying to copy sets of csv files between two states (ex. Arizona and Utah) based on the output shown on the second row/first row (after header) of csv files (where it has "State" column).

I have bunches of csv files that belong to Arizona.

IUser's image

And, I have bunches of csv files that belong to Utah.

User's image

I guess in SQL, it would be something like this:

select distinct top 1 State

from [Table] order by State desc

Now, I am trying to possibly use this type of flow (Lookup --> Set variable) to get the desired value, then, I will copy files into two different folders.

User's image

I created a new dataset (delimited) and created a parameter called "FirstRow".

What would be an expression inside Lookup?

User's image

Also, would Lookup work for going thru pool of multiple csv files or do I have to use ForEach?

Thanks.

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

Answer accepted by question author
  1. Subashri Vasudevan 11,306 Reputation points Volunteer Moderator
    2023-08-11T01:53:25.3433333+00:00

    Hi, yes you would need a foreach loop, that runs in sequential mode. Inside for loop, have a look up activity and set variable.

    1. In the data set that you use for lookup, no need to have a parameter for first row (as you have shown in the ss). So remove the dataset parameter. In your case probably you will need a parameter for current filename that tthe loop brings.
    2. Make sure to check first row as header in the same dataset
    3. Now in the look up activity, check First row only check box (tis is like select top 1 * in sql)
    4. Next to look up have a set variable, use the below expression

    @activity('Lookup1').output.firstRow.State

    This would give you the state information in each file stored on a variable. (Based on your use case for the variable value, can avoid it and make the loop run parallel too. So let us know what you do with the variable value)

    Please let us know if this helps.

    Thanks.

    1 person found this answer helpful.

0 additional answers

Sort by: Most 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.