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

Power BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. Register now.

Reply
Anonymous
Not applicable

Conditional Filtering

Hello everyone,

 

I got this [Date] column and I would like to filter it but conditionally, if today is Monday so I need it to filter [Date] to keep only Sunday’s, Saturday’s and Friday’s entries that preceded today only, otherwise, to filter [Date] to keep only yesterday’s entries, how to do that?

 

Another question related to data models in excel, is there a way to load them in tables, not power pivot?

1 ACCEPTED SOLUTION
edhans
Super User
Super User

Add a new blank query and go to the advanced editor. Delete all the code and paste this in:

let
    Source = if Date.DayOfWeek(DateTime.LocalNow(), Day.Monday) = 0 then Date.AddDays(DateTime.Date(DateTime.LocalNow()), -3) else Date.AddDays(DateTime.Date(DateTime.LocalNow()), -1)
in
    Source

If today is Monday, it will return a day 3 days in the past, otherwise 1 day in the past.

Call this query varDate. Set it not to load.

 

Now, go to your data and filter for any day to get the filter to work. Remove whatever date you selected (it might say #date(2022,3,25) - remove that code and use varDate.

It might look like this:

Table.SelectRows(#"Added Custom", each ([Dates] = varDate))

On the 2nd question, no. You can create a flat pivot table, but not a pure table. Those must come direclty from Power Query, not Power Query to Power Pivot then down to and Excel sheet.



Did I answer your question? Mark my post as a solution!
Did my answers help arrive at a solution? Give it a kudos by clicking the Thumbs Up!

DAX is for Analysis. Power Query is for Data Modeling


Proud to be a Super User!

MCSA: BI Reporting

View solution in original post

1 REPLY 1
edhans
Super User
Super User

Add a new blank query and go to the advanced editor. Delete all the code and paste this in:

let
    Source = if Date.DayOfWeek(DateTime.LocalNow(), Day.Monday) = 0 then Date.AddDays(DateTime.Date(DateTime.LocalNow()), -3) else Date.AddDays(DateTime.Date(DateTime.LocalNow()), -1)
in
    Source

If today is Monday, it will return a day 3 days in the past, otherwise 1 day in the past.

Call this query varDate. Set it not to load.

 

Now, go to your data and filter for any day to get the filter to work. Remove whatever date you selected (it might say #date(2022,3,25) - remove that code and use varDate.

It might look like this:

Table.SelectRows(#"Added Custom", each ([Dates] = varDate))

On the 2nd question, no. You can create a flat pivot table, but not a pure table. Those must come direclty from Power Query, not Power Query to Power Pivot then down to and Excel sheet.



Did I answer your question? Mark my post as a solution!
Did my answers help arrive at a solution? Give it a kudos by clicking the Thumbs Up!

DAX is for Analysis. Power Query is for Data Modeling


Proud to be a Super User!

MCSA: BI Reporting

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

Check out the June 2025 Power BI update to learn about new features.

June 2025 community update carousel

Fabric Community Update - June 2025

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

Top Solution Authors