How to write an expression to include certain words within If Condition (by listing multiple cases)?

Justin Doh 880 Reputation points
2023-08-22T05:11:16.5566667+00:00

Hi

I am trying to find a better way than using some other method (than bottom logic (firstRow) because when I built the pipeline using firstRow, it took a while to process (30 min for about 50 csv files).

I think it took a while because it has to go into each csv files and check the first row, but I am not sure.

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

This is related to what I posted earlier:

https://learn.microsoft.com/en-us/answers/questions/1344088/how-to-write-expression-to-get-the-output-of-2nd-r

Basically, I have about 13 files with all different names of locations (with some certain pattern).

I am now trying to see if I could use something like this (possibly using "Item Name", I am not sure):

User's image

How do I write an expression to list possibly 13 of them having certain words within If Condition expression area?

Basically, I am using "Item name" as Argument, but I am not sure this is the way to go.

Example: words like "LosAngeles", "NewYork" etc (11 more). in between?

For example:

"Payroll_Detail_LosAngeles_20230821.csv" OR

"Payroll_Detail_NewWork_20230821.csv" OR...

How do I write for an expression using Item name inside this Expression area using some logic like this?

@ concat('Payroll_Detail_LosAngeles_', formatDateTime(utcNow(),;yyyyMMdd'),'.csv')

or

@ concat('Payroll_Detail_NewYork_', formatDateTime(utcNow(),;yyyyMMdd'),'.csv')

or

@ concat('Payroll_Detail_SanFrancisco_', formatDateTime(utcNow(),;yyyyMMdd'),'.csv')

or ..(8 more)

User's image

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

1 answer

Sort by: Most helpful
  1. Amira Bedhiafi 41,121 Reputation points Volunteer Moderator
    2023-08-22T09:43:57.9266667+00:00

    You can use the in function in combination with array to check if a specific part of your file name is within a predefined list of values.

    @in(substring(@item().name, indexOf(@item().name, 'Payroll_Detail_') + len('Payroll_Detail_'), indexOf(@item().name, '_', indexOf(@item().name, 'Payroll_Detail_') + len('Payroll_Detail_')) - indexOf(@item().name, 'Payroll_Detail_') - len('Payroll_Detail_')), array('LosAngeles', 'NewYork', 'SanFrancisco', ...))
    
    

    The indexOf function to find the index of the specific pattern 'Payroll_Detail_' in the file name.

    The substring function extracts the part of the file name that corresponds to the location (for example 'LosAngeles', 'NewYork', 'SanFrancisco'....

    The in function will check if the extracted part is within an array containing the list of valid locations.

    It will returntrue if the extracted location is in the predefined list, otherwise returns false.


    Update :

    I thought about using a Switch expression instead of using multiple if conditions.

    First, create an array parameter Cities to hold the list of cities you want to work with.

    Then, use a ForEach activity to iterate over the cities array, and within that, you can use a Switch expression to create the file name based on the city's name.

    "Cities": [
      "LosAngeles",
      "NewYork",
      "SanFrancisco",
      // ... 10 more cities
    ]
    
    // In ForEach activity, iterate over the array
    @parameters('Cities')
    
    // Inside the iteration (ForEach activity), use the Switch expression to build the filename
    @concat('Payroll_Detail_', item(), '_', formatDateTime(utcNow(),'yyyyMMdd'), '.csv')
    
    

    the item() function inside the ForEach loop will return the current city being iterated over and be used to construct the filename.

    The concat function puts together the required string, including the date in the desired format, resulting in the filenames you provided in your examples.


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.