Forum Discussion
WorkingDays Logic Issue
Dear All,
My requirement is to calculate WorkingDays between two dates excluding weekends.
| startdate | enddate | WorkingDays |
| 4/6/2020 | 4/7/2020 | 2 |
| 5/21/2020 | 0 | |
| 5/21/2020 | 5/21/2020 | 1 |
| 5/21/2020 | 5/29/2020 | 7 |
below expression is giving error, "The start date or end date in Calendar function can not be Blank value."
WorkingDays =
VAR YourDate = if(Table[enddate]= BLANK(),BLANK(),Table[enddate])
RETURN
COUNTROWS (
FILTER (
ADDCOLUMNS ( CALENDAR ( Table[startdate], YourDate ), "Day of Week", WEEKDAY ( [Date], 1) ),
[Day of Week] <> 1
&& [Day of Week] <> 7
)
)
Please guide me.
Suren
Hi, Anonymous ;
You could modify the dax as follows:
WorkingDays = VAR YourDate = IF ( [enddate] = BLANK (), [startdate], [enddate] ) var _count= COUNTROWS ( FILTER ( ADDCOLUMNS ( CALENDAR ( [startdate], YourDate ), "Day of Week", WEEKDAY ( [Date], 1 )), [Day of Week] <> 1&& [Day of Week] <> 7) ) return IF([enddate]=BLANK(),0,_count)The final output is shown below:
Best Regards,
Community Support Team_ Yalan Wu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
8 Replies
- mahoneypatMicrosoft Employee
Please try this column expression instead. Replace WD with your actual table name.
WDays =
VAR enddate =
IF ( ISBLANK ( WD[enddate] ), TODAY (), WD[enddate] )
VAR result =
COUNTROWS (
FILTER (
CALENDAR ( WD[startdate], enddate ),
WEEKDAY ( [Date] ) IN { 1, 2, 3, 4, 5 }
)
)
RETURN
IF ( ISBLANK ( WD[enddate] ), 0, result )Pat
- AnonymousNot applicable
Thank you Pat. your expression works but not expected
when there is any future dates in startdate i.e startdate greater than enddate (startdate>enddate) ex:(9/10/2021 > 9/8/2021).
If there is any future dates in startdate make startdate as blank and also for any blanks in either startdate or enddate we replace them with blanks/0 but not with Today()
Please suggest
- AnonymousNot applicable
Any suggestions please
- v-yalanwu-msftCommunity Support
Hi, Anonymous ;
You could modify the dax as follows:
WorkingDays = VAR YourDate = IF ( [enddate] = BLANK (), [startdate], [enddate] ) var _count= COUNTROWS ( FILTER ( ADDCOLUMNS ( CALENDAR ( [startdate], YourDate ), "Day of Week", WEEKDAY ( [Date], 1 )), [Day of Week] <> 1&& [Day of Week] <> 7) ) return IF([enddate]=BLANK(),0,_count)The final output is shown below:
Best Regards,
Community Support Team_ Yalan Wu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.