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

Get certified in Microsoft Fabric—for free! For a limited time, get a free DP-600 exam voucher to use by the end of 2024. Register now

Reply
Anonymous
Not applicable

Filter days based on weekday

Hi Everyone,

 

I have a scenario wherein I want to filter the data on date column based on current day in the query editor.

 

If refreshing on Monday, filter data from last 3 days(Sunday, Saturday & Friday) of date column.

If refreshing on any other day(Tuesday to Friday), filter data from last 1 day of date column.

 

I tried both these & they work individually, but unfortunately I`m unable to get the desired result without changing these frequently.

 

1.

= Table.SelectRows(#"Added Custom4", each [StartDate] >= Date.From(Date.AddDays(Date.From(DateTime.LocalNow()),-Date.DayOfWeek(Date.From(DateTime.LocalNow()),5))))

 

2.

= Table.SelectRows(#"Added Custom4", each [StartDate] >= Date.From(Date.AddDays(DateTime.LocalNow(), -1)))

 

Expected Output

For eg, today is 03rd Mar (Thursday) the report should filter dates greater than 02nd Mar (Wednesday) & if today is 28 Feb (Monday) then report filters date greater than 25 Feb (Friday)

 

Items.png

 

Please help !!

 

Thanks in advance 😊

 

1 ACCEPTED SOLUTION

@Anonymous , Try = Table.SelectRows(#"Added Custom", each [StartDate] >= Date.From(Date.AddDays(DateTime.LocalNow(), (-1 * (if Date.DayOfWeek(DateTime.Date(DateTime.FixedLocalNow())) =0 then 3 else 1 )))))

Join us as experts from around the world come together to shape the future of data and AI!
At the Microsoft Analytics Community Conference, global leaders and influential voices are stepping up to share their knowledge and help you master the latest in Microsoft Fabric, Copilot, and Purview.
️ November 12th-14th, 2024
 Online Event
Register Here

View solution in original post

5 REPLIES 5
amitchandak
Super User
Super User

@Anonymous , Try like

 

Table.SelectRows(#"Added Custom4", each [StartDate] >= Date.From(Date.AddDays(DateTime.LocalNow(), -1* if Date.DayOfWeek(DateTime.Date(DateTime.LocalNow())) =0 then 3 else 1)))

Join us as experts from around the world come together to shape the future of data and AI!
At the Microsoft Analytics Community Conference, global leaders and influential voices are stepping up to share their knowledge and help you master the latest in Microsoft Fabric, Copilot, and Purview.
️ November 12th-14th, 2024
 Online Event
Register Here
Anonymous
Not applicable

Thanks Amit. I tried the formula & unfortuantely got a syntax error. Please assist

Items.png

@Anonymous , Try = Table.SelectRows(#"Added Custom", each [StartDate] >= Date.From(Date.AddDays(DateTime.LocalNow(), (-1 * (if Date.DayOfWeek(DateTime.Date(DateTime.FixedLocalNow())) =0 then 3 else 1 )))))

Join us as experts from around the world come together to shape the future of data and AI!
At the Microsoft Analytics Community Conference, global leaders and influential voices are stepping up to share their knowledge and help you master the latest in Microsoft Fabric, Copilot, and Purview.
️ November 12th-14th, 2024
 Online Event
Register Here
Anonymous
Not applicable

This works like a charm. Had to change the DayOfWeek to get the desired results. Thanks a ton!!

lbendlin
Super User
Super User

Please provide sanitized sample data that fully covers your issue. If you paste the data into a table in your post or use one of the file services it will be easier to work with. Avoid posting screenshots of your source data if possible.

Please show the expected outcome based on the sample data you provided. Screenshots of the expected outcome are ok.


Helpful resources

Announcements
November Carousel

Fabric Community Update - November 2024

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

Live Sessions with Fabric DB

Be one of the first to start using Fabric Databases

Starting December 3, join live sessions with database experts and the Fabric product team to learn just how easy it is to get started.

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! Early Bird pricing ends December 9th.

Nov PBI Update Carousel

Power BI Monthly Update - November 2024

Check out the November 2024 Power BI update to learn about new features.