Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

The Power BI DataViz World Championships are on! With four chances to enter, you could win a spot in the LIVE Grand Finale in Las Vegas. Show off your skills.

Reply
StrPod
Frequent Visitor

How to apply date filter on a date column based on another cutoff date column

I have two columns (date,cutoff).

 

scenario: date column has  dates ranging from (2/1/2021 - 2/1/2002) the cutoff is basically current subtract 2 months (date.addMonth(DateTime.LocalNow(), -2). Which ends up listing exactly one date in every row.

Now in PQ editor when I do date filter on the "date" column > I custom filter > advanced  then column = cutoff

operator = is after

value = the date on cutoff.


I get zero rows returned. Instead of getting last two months of data. Can someone tell me what I am doing wrong? I tried to research but the only closest is this article but im not sure how to convert it to my scenario 

 

Both columns are of date type with no errors 


assume current date is 2/2/2021, just for the purpose of this scenario 

 

 

 

 

 

 

1 ACCEPTED SOLUTION
v-weiyan1-msft
Community Support
Community Support

Hi @StrPod ,

 

Based on your description, the operation you did in PQ editor did not return your expected result, which is to return the rows where the Date column is after the Cutoff column date. The reason is that the column you applied the filter to is not the Date column, but the Cutoff column.

I’m not sure if you created the cutoff column for filtering or other purposes.
But if you want to use dynamic filtering to return data from the two months before the current date, you can consider the following method.

Here is the dummy data I created.

vweiyan1msft_0-1708412770790.png

vweiyan1msft_1-1708412785367.png

The code in the Power Query advanced editor is below.

#"SelectRows" = Table.SelectRows(#"Changed Type", each [Date] > Date.From (Date.AddMonths (DateTime.LocalNow (), -2)))

vweiyan1msft_2-1708412892699.png

Result is as below.

vweiyan1msft_3-1708412908905.png

For further details,please find attachment.
Or you can consider using Relative Date Slicer.
For more you may refer to:

Create a relative date slicer or filter in Power BI - Power BI | Microsoft Learn


Best Regards,
Yulia Yan


If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

2 REPLIES 2
v-weiyan1-msft
Community Support
Community Support

Hi @StrPod ,

 

Based on your description, the operation you did in PQ editor did not return your expected result, which is to return the rows where the Date column is after the Cutoff column date. The reason is that the column you applied the filter to is not the Date column, but the Cutoff column.

I’m not sure if you created the cutoff column for filtering or other purposes.
But if you want to use dynamic filtering to return data from the two months before the current date, you can consider the following method.

Here is the dummy data I created.

vweiyan1msft_0-1708412770790.png

vweiyan1msft_1-1708412785367.png

The code in the Power Query advanced editor is below.

#"SelectRows" = Table.SelectRows(#"Changed Type", each [Date] > Date.From (Date.AddMonths (DateTime.LocalNow (), -2)))

vweiyan1msft_2-1708412892699.png

Result is as below.

vweiyan1msft_3-1708412908905.png

For further details,please find attachment.
Or you can consider using Relative Date Slicer.
For more you may refer to:

Create a relative date slicer or filter in Power BI - Power BI | Microsoft Learn


Best Regards,
Yulia Yan


If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

amitchandak
Super User
Super User

@StrPod , BAsed on what I got.

 

First filter based on date any date , you will get a step

= Table.SelectRows(#"Added Custom", each [Sales Date] > #date(2024, 2, 17))

 

then manually edit it like

 

= Table.SelectRows(#"Added Custom", each [Sales Date] > Date.AddMonths(DateTime.LocalNow(), -2))

Full Power BI Video 20 Hours YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Feb2025 Sticker Challenge

Join our Community Sticker Challenge 2025

If you love stickers, then you will definitely want to check out our Community Sticker Challenge!

Feb2025 NL Carousel

Fabric Community Update - February 2025

Find out what's new and trending in the Fabric community.