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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
slyfox
Helper II
Helper II

Working Days except list of dates

Dear Community,

 

Please help to figure out what is wrong with formula I have

WorkingDays =
var month = month(D_Date[LINK_Date])
var year = year(D_Date[LINK_Date])
return
CALCULATE(COUNTROWS(D_Date), filter( all(D_Date[LINK_Date]), D_Date[LINK_Date]<MAX(D_Date[LINK_Date]) &&YEAR(D_Date[LINK_Date])=year&& MONTH(D_Date[LINK_Date])=month ))

Expected result: Get a new column with Number of passed working days of Month,
Saturday and Sundays always Not working days
additionally few known holiday dates per month 
like this

LINK_Date  WeekDayName  WorkingDayCount
1-May-19Wednesday 
2-May-19Thursday1
3-May-19Friday 
4-May-19Saturday 
5-May-19Sunday 
6-May-19Monday2
7-May-19Tuesday3
8-May-19Wednesday4
9-May-19Thursday5
10-May-19Friday6
11-May-19Saturday 
12-May-19Sunday 
13-May-19Monday7
14-May-19Tuesday8
15-May-19Wednesday9
16-May-19Thursday10
17-May-19Friday11
18-May-19Saturday 
19-May-19Sunday 
20-May-19Monday12
21-May-19Tuesday13
22-May-19Wednesday14
23-May-19Thursday15
24-May-19Friday16
25-May-19Saturday 
26-May-19Sunday 
27-May-19Monday17
28-May-19Tuesday18
29-May-19Wednesday19
30-May-19Thursday20
31-May-19Friday21

pbix file   https://wetransfer.com/downloads/29acdb38499b8ddff1eefd1b6dcc6e2020190516204914/701b113e64c1c1c2ca94...
1 ACCEPTED SOLUTION
Anonymous
Not applicable

You can use this Calculated Column:

WorkingDayCount = 
Var __CurrentDate = 'Table'[Date]
Var __CurrentMonth = 'Table'[MonthName]
Var __CurrentYear = YEAR( 'Table'[Date] )
Var __CurrentDay = 'Table'[DayofWeek] 
Var __List= {"Saturday" , "Sunday" }
RETURN

CALCULATE(
    COUNTROWS( 'Table' ),
    Filter( 
        ALL( 'Table'),
        __CurrentDate >= 'Table'[Date]
        && NOT 'Table'[DayofWeek] IN __List
        && NOT __CurrentDay IN __List
        && __CurrentMonth = 'Table'[MonthName]
        && __CurrentYear = Year( 'Table'[Date])
)
)

Runnign Count of Working Datys.png 

View solution in original post

2 REPLIES 2
edhans
Super User
Super User

This will tell you the weekday count (M-F), but you'd need a separate table to link to this one to explicitly call out holidays and exclude this from the data as well.

WorkingDays = 
CALCULATE(COUNTROWS(D_Date),
    FILTER(
        ALL(D_Date[LINK_Date]),
        DAY(D_Date[LINK_Date])<=D_Date[DATE_DayNumberInMonth]
        && YEAR(D_Date[LINK_Date])=D_Date[DATE_YearNumber]
        && MONTH(D_Date[LINK_Date])=D_Date[DATE_MonthNumber]
        && WEEKDAY(D_Date[LINK_Date],2) <> 6
        && WEEKDAY(D_Date[LINK_Date],2) <> 7
    )
)

I'd also be inclined to do this in Power Query - at least using that to define what is and isn't a workday returning a 1/0 or True/False.

See this post here and the related PBIX file as it is very similar to what you are describing. It has the holiday table in it.



Did I answer your question? Mark my post as a solution!
Did my answers help arrive at a solution? Give it a kudos by clicking the Thumbs Up!

DAX is for Analysis. Power Query is for Data Modeling


Proud to be a Super User!

MCSA: BI Reporting
Anonymous
Not applicable

You can use this Calculated Column:

WorkingDayCount = 
Var __CurrentDate = 'Table'[Date]
Var __CurrentMonth = 'Table'[MonthName]
Var __CurrentYear = YEAR( 'Table'[Date] )
Var __CurrentDay = 'Table'[DayofWeek] 
Var __List= {"Saturday" , "Sunday" }
RETURN

CALCULATE(
    COUNTROWS( 'Table' ),
    Filter( 
        ALL( 'Table'),
        __CurrentDate >= 'Table'[Date]
        && NOT 'Table'[DayofWeek] IN __List
        && NOT __CurrentDay IN __List
        && __CurrentMonth = 'Table'[MonthName]
        && __CurrentYear = Year( 'Table'[Date])
)
)

Runnign Count of Working Datys.png 

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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