Forum Discussion

Syndicate_Admin's avatar
Syndicate_Admin
Icon for Administrator rankAdministrator
2 years ago
Solved

Power Query Date filter for not older than Today - 150 Days

I am trying to create a date filter to exclude items where the date is greater than today - 150 days.

Based on some research, I have come up with the below; however, it is excluding Today!

Any help would be greatly appreciated 

 

= Table.SelectRows(#"Sorted Rows", each Date.IsInPreviousNDays([Finish Date], 150) or Date.IsInNextNDays([Finish Date], 1000))

  • Hi Syndicate_Admin  DonalMc 

     

    I'm a bit confused. You want to exclude rows wheer the date is greater than today -150?  But your code keeps those rows?

     

    Your code will exclude today because today falls inside yoru exclusion criteria.  Today's date is greater than today - 150 days.

     

    To keep rows where the date is greater than today -150

     

    = Table.SelectRows(#"Sorted Rows", each Date.IsInPreviousNDays([Finish Date], 150) or [Finish Date] = Date.From(DateTime.LocalNow()))

     

    To exclude these rows

     

    = Table.SelectRows(#"Sorted Rows", each not (Date.IsInPreviousNDays([Finish Date], 150) or [Finish Date] = Date.From(DateTime.LocalNow())))

     

    Phil 

  • Hi Phil,

    Yes - apologies for my clumsiness - I was trying to exclude items that were less than today -150, i.e. only show items that had a date greater than today - 150 days.

    Your code helped me, but for some reason excluded items after today. I adapted your code and to the below and now have the result I need.

    Thanks for the help

     

    = Table.SelectRows(#"Sorted Rows", each Date.IsInPreviousNDays([Finish Date], 150) or [Finish Date] = Date.From(DateTime.LocalNow()) or Date.IsInNextNDays([Finish Date], 900000) )

2 Replies

  • Hi Syndicate_Admin  DonalMc 

     

    I'm a bit confused. You want to exclude rows wheer the date is greater than today -150?  But your code keeps those rows?

     

    Your code will exclude today because today falls inside yoru exclusion criteria.  Today's date is greater than today - 150 days.

     

    To keep rows where the date is greater than today -150

     

    = Table.SelectRows(#"Sorted Rows", each Date.IsInPreviousNDays([Finish Date], 150) or [Finish Date] = Date.From(DateTime.LocalNow()))

     

    To exclude these rows

     

    = Table.SelectRows(#"Sorted Rows", each not (Date.IsInPreviousNDays([Finish Date], 150) or [Finish Date] = Date.From(DateTime.LocalNow())))

     

    Phil 

  • Hi Phil,

    Yes - apologies for my clumsiness - I was trying to exclude items that were less than today -150, i.e. only show items that had a date greater than today - 150 days.

    Your code helped me, but for some reason excluded items after today. I adapted your code and to the below and now have the result I need.

    Thanks for the help

     

    = Table.SelectRows(#"Sorted Rows", each Date.IsInPreviousNDays([Finish Date], 150) or [Finish Date] = Date.From(DateTime.LocalNow()) or Date.IsInNextNDays([Finish Date], 900000) )