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
ianneg77
Frequent Visitor

How to calculate net working days

I need to calculate the number of days between two date fields EXCLUDING weekends. I have tried a bunch of times but can't seem to get it correct. It is a simple single data table with an "Order Date" field and "Invoice Date" field. I just want to know the number of work days between them. I know I can subtract to get total days but I need to take out the weekend days for it to be accurate for my purposes.

 

I do not want to use or import a separate Calendar Table to do this, since I have both required date fields in the original data table. Excel can do this quite easily but Power BI should have a simpler way to do it. Am I missing something?

 

i.e. An Order Date = 12/6/17 & Invoice Date = 1/9/2018 - is 34 days, but is really "24" week days.....

Capture.JPG

 

 

 

 

 

 

 

1 ACCEPTED SOLUTION

Hi @ianneg77

 

Assuming you have  a calendar table, then you could create a calculated column with the formula provided by @robenanderson to calculated the workdays.

 

workdayflag = if(
    weekday(
       'DateTable'[date]) = 1,0,
             if(
                 weekday(
                       'DateTable'[date])=7,0,1)
)

Then you could create the networkdays column by the formula below.

 

networkdays =
CALCULATE (
    SUM ( 'DateTable'[workdayflag] ),
    DATESBETWEEN ( 'DateTable'[Date], 'Table1'[orderdate], 'Table1'[invoice date] )
)
    - 1

Capture.PNG

 

Hope this can help you!

 

Best Regards,

Cherry

Community Support Team _ Cherry Gao
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

4 REPLIES 4
robenanderson
Frequent Visitor

could you create a table (or add to a calendar table) a flag if it is a working day? for example, If M-F then 1, otherwise Sat and Sun would be 0? Then, do a calculate with the sum set to that workday flag, and a filter to the date is greater than or equal to the Order date and another filter that is less than or equal to the invoice date?

 

utilize this article for calculate with multiple filters.

I do have a calendar file I can add to. But I am not great with DAX yet been using Power BI a few months, so when it comes to filtering I may be in the weeds some.

Hi @ianneg77

 

Assuming you have  a calendar table, then you could create a calculated column with the formula provided by @robenanderson to calculated the workdays.

 

workdayflag = if(
    weekday(
       'DateTable'[date]) = 1,0,
             if(
                 weekday(
                       'DateTable'[date])=7,0,1)
)

Then you could create the networkdays column by the formula below.

 

networkdays =
CALCULATE (
    SUM ( 'DateTable'[workdayflag] ),
    DATESBETWEEN ( 'DateTable'[Date], 'Table1'[orderdate], 'Table1'[invoice date] )
)
    - 1

Capture.PNG

 

Hope this can help you!

 

Best Regards,

Cherry

Community Support Team _ Cherry Gao
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

the article I linked shows how to do multiple filters, and I believe it would be something like this. I apologize in advance with my formatting. I'm not a good code formatter.

 

First, here's formula to create workday flag (1 or 0) that you can then sum in next formula. weekday = 1 is Sunday, 7 is Saturday FYI.

 

workdayflag = if(
    weekday(
         calendartable[date]) = 1,0,
             if(
                 weekday(
                       calendartable[date])=7,0,1)
)

 

then, based on the article I linked, something like this should work

 

DaysBetween MEASURE = 
CALCULATE (
    SUM ( calendar[workdayflag] ),
    FILTER ( INFOTABLE, INFOTABLE[ORDER DATE] >= calendar[DATE] && INFOTABLE[INVOICE DATE] <= calendar[DATE] )
)

 

These should at least get you close to what you're looking for. Be sure to create measure of this. You may need to create another date column or something that can have a relationship connected to it, but I could be wrong in that. Like you, I haven't been working with Power BI for more than a few months. With that said, someone more experienced may have something better to add to this, or something easier.

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.