cancel
Showing results for
Did you mean:
Highlighted
Post Partisan

## Working Days between two periods

Hello  -  This formula works for counting positive days between two periods  (weekdays only).     Meaning...this assumes the Delivery Date comes after the Order Date.

I am actually using this formula for tracking on-time shipments....so some early shipments actually ship before the due date.    In this case, this formula just shows a blank result.    I need it to somehow also count the number of weekdays even if the actual ship date comes before the due date.      For example:      Due Date:   Feb 17    Actual Ship Date:   Feb 12      Even if it shows the result with a negative....like   - 3 Days   this is fine.

Any ideas?

Sales DeliveryWorking Days =
CALCULATE(
COUNTROWS ( DateTable),
DATESBETWEEN ( DateTable[Date],  'Flu Shipped'[Due Date], 'Flu Shipped'[Date Shipped] -0 ),
DateTable[DateIsWorkingDay] = TRUE,
ALL ( 'Flu Shipped' )
)

2 ACCEPTED SOLUTIONS

Accepted Solutions
Super User III

## Re: Working Days between two periods

It should work like you did before.

As I had to build the sample data from scratch, I've allowed myself to skip that additional column.

If you liked my solution, please give it a thumbs up. And if I did answer your question, please mark my post as a solution. Thanks!

Imke Feldmann

How to integrate M-code into your solutionCheck out more PBI- learning resources here -- Performance Tipps for M-queries

Post Partisan

## Re: Working Days between two periods

Thank you Imke!!     Here is the final formula for anyone else that may need this.    Again, this counts the number of workdays between one period and the next   (in this...between Due Dates  and  Ship Dates).     And also accounts for if the ship date comes earlier than the due date.

WDC =
If( 'Flu Shipped'[Due Date] < 'Flu Shipped'[Date Shipped],
CALCULATE(
COUNTROWS( DateTable ),
DATESBETWEEN ( DateTable[Date],  'Flu Shipped'[Due Date], 'Flu Shipped'[Date Shipped]),DateTable[DateIsWorkingDay]= True,
ALL ( 'Flu Shipped' )
),

CALCULATE(
COUNTROWS( DateTable ),
DATESBETWEEN ( DateTable[Date], 'Flu Shipped'[Date Shipped], 'Flu Shipped'[Due Date]), DateTable[DateIsWorkingDay]=True,
ALL ( 'Flu Shipped' )
) * -1)
9 REPLIES 9
Super User III

## Re: Working Days between two periods

WD = if (

'Flu Shipped'[Due Date] < 'Flu Shipped'[Date Shipped],
CALCULATE(
COUNTROWS ( DateTable),
DATESBETWEEN ( DateTable[Date],  'Flu Shipped'[Due Date], 'Flu Shipped'[Date Shipped] -0 ),
DateTable[DateIsWorkingDay] = TRUE,
ALL ( 'Flu Shipped' ),

CALCULATE(
COUNTROWS ( DateTable),
DATESBETWEEN ( DateTable[Date], 'Flu Shipped'[Date Shipped] -0,  'Flu Shipped'[Due Date],  ) * -1,
DateTable[DateIsWorkingDay] = TRUE,
ALL ( 'Flu Shipped'
) )

If you liked my solution, please give it a thumbs up. And if I did answer your question, please mark my post as a solution. Thanks!

Imke Feldmann

How to integrate M-code into your solutionCheck out more PBI- learning resources here -- Performance Tipps for M-queries

Post Partisan

## Re: Working Days between two periods

I tried it.   I am getting the error:

A function "Calculate" has been used in a True/False expression that is used as a Table filter expression.   This is not allowed.

Super User III

## Re: Working Days between two periods

Oh yes, sorry - the *-1 has to be moved:

``````WD = if (

'Flu Shipped'[Due Date] < 'Flu Shipped'[Date Shipped],

CALCULATE(
COUNTROWS ( DateTable),
DATESBETWEEN ( DateTable[Date],  'Flu Shipped'[Due Date], 'Flu Shipped'[Date Shipped] -0 ),
DateTable[DateIsWorkingDay] = TRUE,
ALL ( 'Flu Shipped' ),

CALCULATE(
COUNTROWS ( DateTable),
DATESBETWEEN ( DateTable[Date], 'Flu Shipped'[Date Shipped] -0,  'Flu Shipped'[Due Date],  ) ,
DateTable[DateIsWorkingDay] = TRUE,
ALL ( 'Flu Shipped'
) * -1 )``````

If you liked my solution, please give it a thumbs up. And if I did answer your question, please mark my post as a solution. Thanks!

Imke Feldmann

How to integrate M-code into your solutionCheck out more PBI- learning resources here -- Performance Tipps for M-queries

Post Partisan

## Re: Working Days between two periods

Hi Imke  -  I'm still getting the same message.

I think maybe it has something to do with the IF statement and the Calculate Statments?

Super User III

## Re: Working Days between two periods

Hi working for me, but there might be typos in my post. Please compare with screenshot:

``````WDC =
If( 'Flu Shipped'[Due Date] < 'Flu Shipped'[Date Shipped],
CALCULATE(
COUNTROWS( 'Calendar' ),
DATESBETWEEN ( Calendar[Date],  'Flu Shipped'[Due Date], 'Flu Shipped'[Date Shipped]),
ALL ( 'Flu Shipped' )
),

CALCULATE(
COUNTROWS( 'Calendar' ),
DATESBETWEEN ( Calendar[Date],   'Flu Shipped'[Date Shipped], 'Flu Shipped'[Due Date]) ,
ALL ( 'Flu Shipped' )
) * -1)``````

.. just be aware that the holiday-filter is missing in my sample..

If you liked my solution, please give it a thumbs up. And if I did answer your question, please mark my post as a solution. Thanks!

Imke Feldmann

How to integrate M-code into your solutionCheck out more PBI- learning resources here -- Performance Tipps for M-queries

Super User IV

## Re: Working Days between two periods

https://community.powerbi.com/t5/Quick-Measures-Gallery/Net-Work-Days/m-p/367362#M109

---------------------------------------

Not the Power BI thought police...

##### I have NEW book! DAX Cookbook from Packt
Over 120 DAX Recipes!

Proud to be a Datanaut!

Post Partisan

## Re: Working Days between two periods

Hi Imke   -   Your formula seems to be counting total days.    I am just looking for week days.     For example, to use your numbers below there are not 32 "work days" between January 1 and Feb 1.

Super User III

## Re: Working Days between two periods

It should work like you did before.

As I had to build the sample data from scratch, I've allowed myself to skip that additional column.

If you liked my solution, please give it a thumbs up. And if I did answer your question, please mark my post as a solution. Thanks!

Imke Feldmann

How to integrate M-code into your solutionCheck out more PBI- learning resources here -- Performance Tipps for M-queries

Post Partisan

## Re: Working Days between two periods

Thank you Imke!!     Here is the final formula for anyone else that may need this.    Again, this counts the number of workdays between one period and the next   (in this...between Due Dates  and  Ship Dates).     And also accounts for if the ship date comes earlier than the due date.

WDC =
If( 'Flu Shipped'[Due Date] < 'Flu Shipped'[Date Shipped],
CALCULATE(
COUNTROWS( DateTable ),
DATESBETWEEN ( DateTable[Date],  'Flu Shipped'[Due Date], 'Flu Shipped'[Date Shipped]),DateTable[DateIsWorkingDay]= True,
ALL ( 'Flu Shipped' )
),

CALCULATE(
COUNTROWS( DateTable ),
DATESBETWEEN ( DateTable[Date], 'Flu Shipped'[Date Shipped], 'Flu Shipped'[Due Date]), DateTable[DateIsWorkingDay]=True,
ALL ( 'Flu Shipped' )
) * -1)

Announcements

#### New Ranks Launched March 24th!

The time has come: We are finally able to share more details on the brand-new ranks coming to the Power BI Community!

#### ‘Better Together’ Contest Finalists Announced!

Congrats to the finalists of our ‘Better Together’-themed T-shirt design contest! Click for the top entries.

#### Arun 'Triple A' Event Video, Q&A, and Slides

Missed the Arun 'Triple A' event or want to revisit it? We've got you covered! Check out the video, Q&A, and slides now.

#### Join THE global Power Platform event series.

Attend for two days of expert-led learning and innovation on topics like AI and Analytics, powered by Dynamic Communities.

#### Community Summit North America

Innovate, Collaborate, Grow. The top training and networking event across the globe for Microsoft Business Applications

Top Solution Authors
Top Kudoed Authors