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

Earn the coveted Fabric Analytics Engineer certification. 100% off your exam for a limited time only!

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.

mahoneypat
Employee
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 { 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 

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".

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. But i am unable to get correct values as shown in column 

NETWORKDAYS(A2,B2)-1

 

Could you please help me here

 

startdateenddateWDaysNETWORKDAYS(A2,B2)-1
4/6/20204/7/202021
5/21/2020 00
5/21/20205/21/202010
5/21/20205/29/2020426
5/21/20206/3/20202209
5/22/2020 00
5/22/20206/3/20203878
5/26/2020 00
6/18/20206/18/202060
8/18/20218/24/2021654
8/18/20218/25/2021425
8/18/20218/26/2021776
8/19/2021 00
8/19/20218/19/20213550
8/19/20218/20/2021771
8/19/20218/21/202191
8/19/20218/23/2021452
8/19/20218/25/2021254
8/20/2021 00

Helpful resources

Announcements
April AMA free

Microsoft Fabric AMA Livestream

Join us Tuesday, April 09, 9:00 – 10:00 AM PST for a live, expert-led Q&A session on all things Microsoft Fabric!

March Fabric Community Update

Fabric Community Update - March 2024

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