Linq Query to Filter future and past date

Hello,

I want to filter the previous and future date from date of completion column.

How to achieve this using Linq Filter

The image is a table listing names, activity IDs, and dates of completion, detailing activities related to fruits like Orange, Apple, Papaya, and Banana on various dates in 2023 and 2024. (Captioned by AI)

Regards,
Sharu

Hi @sharu_priya ,

If you want separate table for past and future table. Use assign activity as follow
dt_PastDates = Table.AsEnumerable.Where(function(r) cdate(r(“Date of Completion”)) < DateTime.Today.Date).CopyToDataTable

dt_FutureDates = Table.AsEnumerable.Where(function(r) cdate(r(“Date of Completion”)) > DateTime.Today.Date).CopyToDataTable

In case your requirement is such that you want all the records except today’s. which means past and future in one single table, use the below code:

dt_NotTodayDates = Table.AsEnumerable.Where(function(r) cdate(r(“Date of Completion”)) <> DateTime.Today.Date).CopyToDataTable

Thanks!!

1 Like

Thank you so much…

What should be the datatype of dtpast and dtfuture

it should be dataTable. also in “Value to Save” field you only need to write the query and not table reference as dt_pastDates.
thus, in “Save to” type in dt_pastDates and in
“Value to Save” - DT1.AsEnumerable.Where(function(r) cdate(r(“Date of Completion”)) < DateTime.Today.Date).CopyToDataTable

1 Like

Thank you…

But getting the below error

I resolved that… It was because i just copy pasted … so i just removed the double quote and typed again. It got worked.

Thank you so much

Great !! thank you for confirming

But why am i getting the output as below…

I need only date of completion column alone

is it because you are giving copy to datatable at the end

@sharu_priya,

Use this workflow:

Added this logic to keep only the required column in the datatable.

dtfutureDates.DefaultView.ToTable(False,"Date of Completion")

Sequence.xaml (12.1 KB)

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