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

We've captured the moments from FabCon & SQLCon that everyone is talking about, and we are bringing them to the community, live and on-demand. Starts on April 14th. Register now

Reply
Anonymous
Not applicable

Calculate difference between two dates excluding weekends using a date table?

This is how I got my working days calculations 

 

I added the working days calculations to a "date" table in my Power BI workbook. However, I do not understand how to use the working days column I now have to determine the difference between two dates. 

Here's my table:

 

jsauerla_0-1601668798289.png

 

 

Here's an example of my Date table:

 

jsauerla_1-1601668833870.png

 

 

 

Since I know the working days (by 1) and the non-working days (0), how can I add another column or a measure (Business Days Elapsed) to see how many working days is between start date and end date? I do not understand this part. 

1 ACCEPTED SOLUTION
calerof
Impactful Individual
Impactful Individual

@Anonymous 

You could use this code:

WorkingDaysDiff = 
VAR BlankDate = ISBLANK(Weekday5[Start Date]) || ISBLANK(Weekday5[End Date])
RETURN
IF(BlankDate, 0,
    CALCULATE(
        COUNTROWS ( 'Calendar'),
        DATESBETWEEN ( 'Calendar'[Date],  'Weekday5'[Start Date], 'Weekday5'[End Date] ),
        'Calendar'["IsWorkingDay"] = TRUE,
        ALL ( 'Weekday5' )
    )
)

And you'll get this result:

weekday.png

Hope it helps.

Regards,

Fernando

 

P.S. If it helped, please consider liking the post and marking it as an answer.

View solution in original post

4 REPLIES 4
mhossain
Solution Sage
Solution Sage

@Anonymous 

 

Try this measure: make sure you change the Table/column names as per your table

 

Business_Days_Elapsed? =
 
SUMX('Table',DATEDIFF('Table'[Start Date],'Table'[End Date],DAY))
-
CALCULATE(COUNT(wDay[Working day]),wDay[Working day]=0,
FILTER(wDay,wDay[Date]>=MAX('Table'[Start Date])),FILTER(wDay,wDay[Date]<=MAX('Table'[End Date])))
calerof
Impactful Individual
Impactful Individual

Hi @Anonymous ,

It's time for you to start your long journey to meet the great SQLBI guys here.

Use this code in a new column in your table:

WorkingDaysDiff = 
CALCULATE(
    COUNTROWS ( 'Calendar'),
    DATESBETWEEN ( 'Calendar'[Date],  'Weekday'[Start Date], 'Weekday'[End Date] ),
    'Calendar'["IsWorkingDay"] = TRUE,
    ALL ( 'Weekday' )
)

You get this:

WorkingdaysDiff.png

Regards,

Fernando

 

Anonymous
Not applicable

@calerof Thank you. This solution worked, but I see one error. If there is no date for either the Weekday[Start Date] or Weekday[End Date], such as if we have no data for the order dates, it sets WorkingDaysDiff to the maximum possible days in the calendar. Since mine goes back 2 years, I have thousands of rows set to 783 now. 

 

How can I default them to 0 if there's no data present? 

calerof
Impactful Individual
Impactful Individual

@Anonymous 

You could use this code:

WorkingDaysDiff = 
VAR BlankDate = ISBLANK(Weekday5[Start Date]) || ISBLANK(Weekday5[End Date])
RETURN
IF(BlankDate, 0,
    CALCULATE(
        COUNTROWS ( 'Calendar'),
        DATESBETWEEN ( 'Calendar'[Date],  'Weekday5'[Start Date], 'Weekday5'[End Date] ),
        'Calendar'["IsWorkingDay"] = TRUE,
        ALL ( 'Weekday5' )
    )
)

And you'll get this result:

weekday.png

Hope it helps.

Regards,

Fernando

 

P.S. If it helped, please consider liking the post and marking it as an answer.

Helpful resources

Announcements
New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

Join our Fabric User Panel

Join our Fabric User Panel

Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.

March Power BI Update Carousel

Power BI Community Update - March 2026

Check out the March 2026 Power BI update to learn about new features.