Filter data table using .AsEnumerable

Hi Experts

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

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?

@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

we can mybe rewrote to the Query syntax

(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:
:ambulance: :sos: [FirstAid] Handling of The source contains no DataRows exception - News / Tutorials - UiPath Community Forum

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

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