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

Data Days is here! Join us now for 60+ days of learning, challenges, and connection. Learn more

Reply
mshashmi
Frequent Visitor

Filter a table

Hi I have a table. It has a date column. Now I want to filter the rows in such a way that I am left with only past 5 dates present in the table.

 

Suppose:

 

Date

12 Feb, 2017

11 June, 2017

9 May, 2017

31 May, 2017

24 March, 2017

19 Jan, 2017

26 April, 2017

 

Now my filtered table should display only past 5 dates and rest rows should be either hidden or removed from the table.

Like I want dates from 9 May, 2017 to 11 June, 2017 to be present and 19 Jan, 2017 and 12 Feb, 2017 to be removed.

 

Thanks

1 ACCEPTED SOLUTION
v-caliao-msft
Microsoft Employee
Microsoft Employee

@mshashmi,

 

You can edit your query, add a custom column on it and filter the new column.

Add a custom column

= Table.AddColumn(#"Changed Type", "Custom.2", each Date.DayOfYear(DateTime.LocalNow())-Date.DayOfYear([Date]))
Filter this column

= Table.SelectRows(#"Added Custom2", each [Custom.2] >= 0 and [Custom.2] <= 4)

Capture.PNG

 

Regards,

Charlie Liao

 

View solution in original post

4 REPLIES 4
v-caliao-msft
Microsoft Employee
Microsoft Employee

@mshashmi,

 

You can edit your query, add a custom column on it and filter the new column.

Add a custom column

= Table.AddColumn(#"Changed Type", "Custom.2", each Date.DayOfYear(DateTime.LocalNow())-Date.DayOfYear([Date]))
Filter this column

= Table.SelectRows(#"Added Custom2", each [Custom.2] >= 0 and [Custom.2] <= 4)

Capture.PNG

 

Regards,

Charlie Liao

 

@v-caliao-msft

 

I am getting error that my Date.DayofYear is not recognized.

@mshashmi,

 

Power query is case sensitive, you need to use Date.DayOfYear

 

Regards,

Charlie Liao

@v-caliao-msft

 

Thanks, it worked.

Helpful resources

Announcements
Fabric Data Days is here Carousel

Fabric Data Days 2026

Don't miss out on Data Days, June 15 through August 7. Learn Fabric, Power BI, SQL, AI and more.

May Power BI Update Carousel

Power BI Monthly Update - May 2026

Check out the May 2026 Power BI update to learn about new features.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.