# Filter data table using .AsEnumerable

**URL:** <https://forum.uipath.com/t/filter-data-table-using-asenumerable/508953>\
**Category:** Activities\
**Tags:** asenumerable, question, excel, system, activities\
**Created:** [January 19, 2023, 1:16pm UTC](https://forum.uipath.com/t/filter-data-table-using-asenumerable/508953 "2023-01-19T13:16:49Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![jacchr](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/jacchr/32/176616_2.png) [@jacchr](https://forum.uipath.com/u/jacchr)\
**Post date:** [January 19, 2023, 1:16pm UTC](https://forum.uipath.com/t/filter-data-table-using-asenumerable/508953/1 "2023-01-19T13:16:49Z")

</div>

Hi Experts

I am reading an Excel file into a data table which I am filtering using the following expression:

```auto
queueData.AsEnumerable.Where(	Function(x) String.Equals(x("SignedUp").ToString.ToLower.Trim, "yes") And 
		String.Equals(x("IsPublic").ToString.ToLower.Trim, "yes") And
		String.IsNullOrEmpty(x("Manual Handling").ToString) And
		Not String.Equals(x("AnswerReceived").ToString.ToLower.Trim, "yes")).CopyToDataTable

```

That part works fine. However I need to add an extra dimension where I also filter on date with the following criteria:

Only include the row if

- the date field is not null (data is originally read from Excel)
- the difference between the date field and today’s date is less than 30 days

How can this be achieved?

---

<div class="post-metadata">

**Author:** ![Anil\_G](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/anil_g/32/524291_2.png) [@Anil\_G](https://forum.uipath.com/u/Anil_G)\
**Post date:** [January 19, 2023, 1:42pm UTC](https://forum.uipath.com/t/filter-data-table-using-asenumerable/508953/2 "2023-01-19T13:42:03Z")

</div>

@jacchr

You have to include like this

`If(IsNullOrEmpty(x("Date").ToString.Trim),"",If(datediff(dateinterval.day,Now,Cdate(x("Date").Tostring)<30,x("date").Tostring,""))`

Hope this helps

Cheers

---

<div class="post-metadata">

**Author:** ![ppr](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/ppr/32/464097_2.png) [@ppr](https://forum.uipath.com/u/ppr)\
**Post date:** [January 19, 2023, 2:11pm UTC](https://forum.uipath.com/t/filter-data-table-using-asenumerable/508953/3 "2023-01-19T14:11:10Z")

</div>

we can mybe rewrote to the Query syntax

```auto
(from r in queueData.AsEnumerable
Where String.Equals(r("SignedUp").ToString.ToLower.Trim, "yes") 
Where String.Equals(r("IsPublic").ToString.ToLower.Trim, "yes") 
Where String.IsNullOrEmpty(r("Manual Handling").ToString) 
Where Not String.Equals(r("AnswerReceived").ToString.ToLower.Trim, "yes")
Where Not (isNothing(r("Date)) OrElse String.IsNullOrEmpty(r("Date").toString.Trim))
Where (Now.Date - CDate(r("Date").toString.Trim)).Days < 30
Select x = r).CopyToDataTable

```

Handling empty result:  
[🚑 🆘 [FirstAid] Handling of The source contains no DataRows exception - News / Tutorials - UiPath Community Forum](https://forum.uipath.com/t/firstaid-handling-of-the-source-contains-no-datarows-exception/410526)

---

<div class="post-metadata">

**Author:** ![jacchr](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/jacchr/32/176616_2.png) [@jacchr](https://forum.uipath.com/u/jacchr)\
**Post date:** [January 20, 2023, 7:18am UTC](https://forum.uipath.com/t/filter-data-table-using-asenumerable/508953/4 "2023-01-20T07:18:19Z")

</div>

Thanks - the rewritten syntax makes much more sense… Very much appreciated!

---

<div class="post-metadata">

**Author:** ![system](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/system/32/182466_2.png) [@system](https://forum.uipath.com/u/system)\
**Post date:** [January 23, 2023, 7:18am UTC](https://forum.uipath.com/t/filter-data-table-using-asenumerable/508953/5 "2023-01-23T07:18:22Z")

</div>

Closed on January 23, 2023, 7:18am UTC

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