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
kasiaw29
Resolver II
Resolver II

Simple way to calculate working days between two dates.

Hi all, 

 

I've search all round this forum to find a simple solution to figure out number of working days between two dates. i.e. excluding weekend. I actually had to use two existing posts and some existing skills to make it a bit easier to understand. 

All dates in my example are hypothetical....Here it goes:

 

Start with creating new table that will act as a calendar 

Next use this in formula bar of newly created table (you're giving it a name and it's first column

MyCalendar =
CALENDAR(MIN('Activivty History'[Latest Baseline Dispatch Date].[Date]),MAX('Sub Project w Activities'[ACTUAL_START].[Date]))
 
Explanation: CALENDAR funtion returns a table that contains a set of dates, it names your column simply as Date, whereas the usage of MIN and MAX indicates your date ranges of your date set. So I'm using MIN date found in Latest Baseline Dispatch Date column and MAX date found in Actual Start column.  You should see something like this so far:
 
2020-06-03_15-48-22.jpg
 
 
 
 
 
 
 
 
 
Next we need to figure out week days within date range we just created. Create new column and copy and paste this:
Week Day = WEEKDAY(MyCalendar[Date].[Date],2)
As per documentation this function "Returns a number from 1 to 7 identifying the day of the week of a date". Syntax for this is:
WEEKDAY(<date>, <return_type>). There are three different return types, read here more about it. I have used 2 in above code as it indicated week beggining on Monday (1) and ending on Sunday (7).
You should now have something like this: 

2020-06-03_15-53-34.jpg

You can see your 6 & 7 which is your Saturday and Sunday (feel free to check the calendar like I did to see if this was right

Next what you want to do is create a simple IF statement that determines if it's a working day or not, so use this:

Working Day = IF(DimDate[Week Day] in {1,2,3,4,5},"True","False")
This IF statement simply goes and checks what the week day is and if it falls within 1-5 range returns True otherwise it returns False. 
 
Now return to your table where you want to figure out your working days between two dates and do this: 
 
WorkingDays Early or Late =
COUNTROWS(
FILTER(MyCalendar,
AND(
AND(
MyCalendar[Date].[Date] >='Activivty History'[Latest Baseline Dispatch Date].[Date],
MyCalendar[Date].[Date] <=RELATED('Sub Project w Activities'[ACTUAL_START].[Date])),

MyCalendar[Working Day])))
 
You're counting number of rows within filtered MyCalendar table you have created where your date range is (in my example) between Latest Baseline Dispatch Date and Actual Start and it only counts the ones that are True  in Working Day calendar. 
 
Hope this helped someone out there! 
 
Thanks
Kasia 
1 REPLY 1
Anonymous
Not applicable

Hi,
I believe that this article from SQL BI is just what you're looking for!

https://www.sqlbi.com/articles/counting-working-days-in-dax/

 

Hope this helps!

Kim

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.

Top Solution Authors