Unable to Filter datatable in one column with 2 date values

Hi Guys,

I want to apply filter in this column with 2 months and 3 months advance from current month. For ex: I need to filter with 11/01/2025 and 12/01/2025, how can we do this?

I am using this below to fetch values of 2 months and 3 months respectively from current month:

I am using this in a “Datetime” datatype, getting correct value as well (Ex: 11/01/2025 and 12/01/2025), but unable to filter in my datatable.

  • Tried converting to .ToString as well (by removing zeroes) but its not filtering. Please suggest.

Not sure, where I am doing wrong here. Kindly suggest. Thanks in advance.

BR,
NK

Hi, @Nitesh Try this in your Assign activity:
filteredDT = MainDt.AsEnumerable.Where(Function(r) DateTime.Parse(r(“BCD”).ToString) = New DateTime(2025, 11, 1) Or DateTime.Parse(r(“BCD”).ToString) = New DateTime(2025, 12, 1)).CopyToDataTable

This will filter your table for rows with BCD as 11/01/2025 or 12/01/2025. Make sure your Excel dates are in the “MM/dd/yyyy” format. This should solve your filtering problem.

Hi @arjun.shiroya ,

  1. Above code is working fine, but I have other columns (approx 7 columns) which I am filtering with this. How will I make sure to pass the above “filteredDT” in activity Filter Datatable?

  1. In your above expression i.e., “New DateTime(2025, 11, 1)” and “New DateTime(2025, 12, 1)”, how will I make this dynamic?

BR,
NK

@Nitesh After you get your filteredDT using Assign and LINQ, you can pass that filteredDT straight into the Filter Data Table activity to keep filtering other columns.

For dynamic dates, just create variables like:

twoMonth = New DateTime(Now.Year, Now.AddMonths(2).Month, 1)
threeMonth = New DateTime(Now.Year, Now.AddMonths(3).Month, 1)
and use those in your filter expression. This keeps your workflow flexible and updates the dates every time you run it.
Please Mark solution if it was helpful.
Cheers

1 Like

Hi @arjun.shiroya ,

Thanks alot for your help. It worked.

Solution: I assigned your LINQ in 1 variable and stored in data table variable (filteredDT) → In filter datatable, I used filteredDT as an input (instead of passing MainDt) and got the result.
NOTE: I didn’t passed filteredDT into my filter datatable activity. (Removed from there as I was already having filtered values after using LINQ).

Much appreciated. Thanks alot.

BR,
NK

1 Like

@Nitesh
Awesome, glad it worked for you! Thanks for letting me know. If you ever get stuck again or need help with something else, just reach out. Happy automating!

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.