Forum Discussion
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?
Yes, like I mentioned - you have to add your workday-filter.
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.
- Anonymous6 years ago
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
- ImkeFCommunity Champion
Hi Anonymous
how about this?
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') )- AnonymousNot applicable
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.
- ImkeFCommunity Champion
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 )