Forum Discussion
Column that Excludes weekends from Dates
I created a Date column that populates each row with the planned delivery date if that date is in the next 7 days.
As such if today is January 26, the column will be populated with dates from Jan-26 to Feb 1. (The next 7 days)
I would like Weekends not to be included. So the next 7 days from Jan 26 should includes Dates from Jan 26 to Feb 3 excluding Jan 29 and Jan 30 (Saturday and Sunday).
Basically the next 7 working days since we don't deliver on weekends.
Any help will be appreciated
- Anonymous4 years ago
Hi vincetaylor ,
Create a related DimDate table and then create a measure to filter your visual.
Date = VAR _Date = ADDCOLUMNS ( CALENDAR ( MIN ( 'Table'[Date] ), MAX ( 'Table'[Date] ) ), "Year", YEAR ( [Date] ), "Month", MONTH ( [Date] ), "YearMonth", YEAR ( [Date] ) * 100 + MONTH ( [Date] ), "Day", DAY ( [Date] ), "DayName", FORMAT ( [Date], "DDDD" ) ) VAR _ADDRANK = ADDCOLUMNS ( _Date, "RANK", VAR _RANK = RANKX ( FILTER ( _Date, NOT ( [DayName] IN { "Saturday", "Sunday" } ) ), [Date], , ASC ) RETURN IF ( NOT ( [DayName] IN { "Saturday", "Sunday" } ), _RANK,_RANK ) ) RETURN _ADDRANKMeasure:
Measure = VAR _DAYNAMETODAY = CALCULATE(MAX('Date'[DayName]),FILTER(ALL('Date'),'Date'[Date] = TODAY())) VAR _RANKTODAY = CALCULATE(SUM('Date'[RANK]),FILTER(ALL('Date'),'Date'[Date] = TODAY())) VAR _RANKADD7 = _RANKTODAY+7 VAR _CURRENTRANK = SUM('Date'[RANK]) RETURN if(_DAYNAMETODAY IN{"Saturday","Sunday"},IF(_CURRENTRANK >=_RANKTODAY&&_CURRENTRANK<_RANKADD7&&NOT(MAX('Date'[DayName])IN{"Saturday","Sunday"}),1,0), IF(_CURRENTRANK >_RANKTODAY&&_CURRENTRANK<=_RANKADD7&&NOT(MAX('Date'[DayName])IN{"Saturday","Sunday"}),1,0))Create a visual, add this measure in visual level filter field and set it to show items when value =1.
Best Regards,
Rico ZhouIf this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
2 Replies
- amitchandakSuper User
vincetaylor , refer if my blog on the same can help
Traveling Across Workdays - What is next/previous Working day
https://community.powerbi.com/t5/Community-Blog/Travelling-Across-Workdays-Decoding-Date-and-Calendar-4-5-Power/ba-p/1187766 - AnonymousNot applicable
Hi vincetaylor ,
Create a related DimDate table and then create a measure to filter your visual.
Date = VAR _Date = ADDCOLUMNS ( CALENDAR ( MIN ( 'Table'[Date] ), MAX ( 'Table'[Date] ) ), "Year", YEAR ( [Date] ), "Month", MONTH ( [Date] ), "YearMonth", YEAR ( [Date] ) * 100 + MONTH ( [Date] ), "Day", DAY ( [Date] ), "DayName", FORMAT ( [Date], "DDDD" ) ) VAR _ADDRANK = ADDCOLUMNS ( _Date, "RANK", VAR _RANK = RANKX ( FILTER ( _Date, NOT ( [DayName] IN { "Saturday", "Sunday" } ) ), [Date], , ASC ) RETURN IF ( NOT ( [DayName] IN { "Saturday", "Sunday" } ), _RANK,_RANK ) ) RETURN _ADDRANKMeasure:
Measure = VAR _DAYNAMETODAY = CALCULATE(MAX('Date'[DayName]),FILTER(ALL('Date'),'Date'[Date] = TODAY())) VAR _RANKTODAY = CALCULATE(SUM('Date'[RANK]),FILTER(ALL('Date'),'Date'[Date] = TODAY())) VAR _RANKADD7 = _RANKTODAY+7 VAR _CURRENTRANK = SUM('Date'[RANK]) RETURN if(_DAYNAMETODAY IN{"Saturday","Sunday"},IF(_CURRENTRANK >=_RANKTODAY&&_CURRENTRANK<_RANKADD7&&NOT(MAX('Date'[DayName])IN{"Saturday","Sunday"}),1,0), IF(_CURRENTRANK >_RANKTODAY&&_CURRENTRANK<=_RANKADD7&&NOT(MAX('Date'[DayName])IN{"Saturday","Sunday"}),1,0))Create a visual, add this measure in visual level filter field and set it to show items when value =1.
Best Regards,
Rico ZhouIf this post helps, then please consider Accept it as the solution to help the other members find it more quickly.