How to use For each to pass variable to Filter wizard of "Filter data table" activity

assume you have 2 excels, one is the main excel , one the the excel containing the names to filter by

this is how you can filter dynamically instead of hardcoding a filter datatable activity

1 read “test.xlsx” to dtMain variable

  1. read “NamesToFilter.xlsx” to dtNamesToFilter datatable variable

  2. initialize a “filterList” and filterString variable

  3. loop over dtNamesToFilter, in each iteraction add "[Name]='"+CurrentRow("Name").ToString+"'" to filterList


    3a. now filteredList looks like this
    image

  4. assign String.Join(" OR ", filterList) to filterString

  5. this should be the value of filterString
    [Name]='John' OR [Name]='Andrew' OR [Name]='Dacia'

  6. now simply assign dtMain.Select(filterString).CopyToDataTable to a new datatable variable: dtFiltered

  7. dtFilter will look like this
    image

Test.xaml (7.9 KB)
NamesToFilter.xlsx (8.3 KB)
Test.xlsx (8.4 KB)

1 Like