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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
arc14
New Member

Filter All Visuals to Previous Business Day

I have a table called dataload_tracking_xto_added with a column called date_released (each row in this table has a date_released value). I would like to add a "yesterday" button and when the user clicks on it all visuals should be filtered to the previous day's date_released. I can use Power BI's relative date filter and just set it to the last 1 day, but this does not handle the case of weekends. If someone checks the dashboard on a Monday or Sunday then the previous day should show Friday's data as there is no data loaded on Saturday or Sunday. I have this query but its not working as expected:
FilterByPreviousBusinessDay =

VAR TodayDate = TODAY()

VAR WeekDay = WEEKDAY(TodayDate , 2)

VAR FilterDate =

IF( WeekDay=1, TodayDate-3, TodayDate -1) -- If today is a Mon then filter to last Friday else filter to previous day

RETURN

IF(SELECTEDVALUE(DATALOAD_TRACKING_XTO_ADDED[DATE_RELEASED] = FilterDate , 1 , 0)

 

I think the problem here is with the last line "IF(SELECTEDVALUE(DATALOAD_TRACKING_XTO_ADDED[DATE_RELEASED] = FilterDate , 1 , 0)", am I using the correct aggregration function? Should I be doing this in PowerQuery instead of a measure?

If this query worked as expected I would navigate to a page where FilterByPreviousBusinessDay = 1 when the user hits the "yesterday" button.

 

1 REPLY 1
lbendlin
Super User
Super User

"Yesterday"  and "previous business day"  can be very different things.  The safest approach is to mark your business days (excluding weekends and holidays) in your calendar table, and then employ the "Penultimate"  pattern (prefeably via the new window functions).

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.