cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
suren947
Helper I
Helper I

WorkingDays Logic Issue

Dear All,

My requirement is to calculate WorkingDays between two dates excluding weekends.

 

startdateenddateWorkingDays
4/6/20204/7/20202
5/21/2020 0
5/21/20205/21/20201
5/21/20205/29/20207

 

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

1 ACCEPTED SOLUTION
v-yalanwu-msft
Community Support
Community Support

Hi, @suren947 ;

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:

vyalanwumsft_0-1632459029192.png

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.

View solution in original post

8 REPLIES 8
v-yalanwu-msft
Community Support
Community Support

Hi, @suren947 ;

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:

vyalanwumsft_0-1632459029192.png

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.

View solution in original post

mahoneypat
Super User
Super User

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 { 12345 }
        )
    )
RETURN
    IF ( ISBLANK ( WD[enddate] )0result )

 

Pat





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


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 

Any suggestions please 

VahidDM
Resident Rockstar
Resident Rockstar

Hi @suren947 

 

Try to add another condition to @mahoneypat measure, if you want to show 0, when startdate is grater than end date or one of those date items is blank:

 

WDays =
VAR enddate =
    IF ( ISBLANK ( WD[enddate] )TODAY (), WD[enddate] )
VAR result =
    COUNTROWS (
        FILTER (
            CALENDAR ( WD[startdate], enddate ),
            WEEKDAY ( [Date] ) IN { 12345 }
        )
    )
RETURN
    IF ( WD[startdate]>WD[enddate]||ISBLANK ( WD[enddate] )||ISBLANK ( WD[startdate] )0result )

 

If this post helps, please consider accepting it as the solution to help the other members find it more quickly.

Appreciate your Kudos✌️!!

Thank you Vahid for your reply but the expression is showing below message. Please help 

"The start date in Calendar function can not be later than the end date".

VahidDM
Resident Rockstar
Resident Rockstar

Hi @suren947 

 

Try this column expression and replace WD with your actual table name.

 

WDays =
IF (
    WD[startdate] > WD[enddate]
        || ISBLANK ( WD[enddate] )
        || ISBLANK ( WD[startdate] ),
    0,
    COUNTROWS (
        FILTER (
            CALENDAR ( WD[startdate], WD[enddate] ),
            WEEKDAY ( [Date] ) IN { 1, 2, 3, 4, 5 }
        )
    )
)

 

If this post helps, please consider accepting it as the solution to help the other members find it more quickly.

Appreciate your Kudos🙏!!

Thank you  Vahid for your responses

Helpful resources

Announcements
UG GA Amplification 768x460.png

Launching new user group features

Learn how to create your own user groups today!

Power BI October Update 2021.jpg

Power BI Release

Click here to read more about the October 2021 Release!

Community Connections 768x460.jpg

Community & How To Videos

Check out the new Power Platform Community Connections gallery!

Teds Dev Camp Oct. 2021 768x460.jpg

Power BI Dev Camp - October 28th, 2021

Mark your calendars and join us for our next Power BI Dev Camp!