Forum Discussion
Day Count Business Days Between Two Dates
- 8 years ago
I intended it as a measure.
The culprit is this statement:
Business Day Value = if('Date'[DayOfWeek]="Monday"||
'Date'[DayOfWeek]="Tuesday"||
'Date'[DayOfWeek]="Wednesday"||
'Date'[DayOfWeek]="Thursday"||
'Date'[DayOfWeek]="Friday",
"1",
"0")This statement results in a string of either "1" or "0". Change this to:
Business Day Value = if('Date'[DayOfWeek]="Monday"|| 'Date'[DayOfWeek]="Tuesday"|| 'Date'[DayOfWeek]="Wednesday"|| 'Date'[DayOfWeek]="Thursday"|| 'Date'[DayOfWeek]="Friday", 1, 0)and make sure that the Business Day Value column in your calendar table is of type Whole Number. That should do it.
Hi Anonymous,
do you have a calendar table in your model? If you do, create a custom column [Workday] in the calendar table that contains 1 for days that are workdays and 0 otherwise. Then change the [Day Count of Drop] to sum up the ones and zeros between the dates, i.e. CALCULATE(SUM(Dates[Workday], FILTER(Dates, xxx[Creation Date] >= Dates[Date] && xxx[Start Date] < Dates[Date]). You still need the test and multiply by -1 to get that part right.
- Anonymous8 years agoNot applicable
Thanks. I created a column and used the following statement:
Business Day Value = if('Date'[DayOfWeek]="Monday"||'Date'[DayOfWeek]="Tuesday"||'Date'[DayOfWeek]="Wednesday"||'Date'[DayOfWeek]="Thursday"||'Date'[DayOfWeek]="Friday","1","0")
I am a little foggy on these two parts:
1. CALCULATE(SUM(Dates[Workday], FILTER(Dates, xxx[Creation Date] >= Dates[Date] && xxx[Start Date] < Dates[Date])
a. Please break down this statement so I understand the functions
2. Not sure what you mean about needing a test and multuply by -1
Thanks!
Can you help me understand with a little more detail?
- erik_tarnvik8 years ago
Solution Specialist
Anonymous
Sure! I think you are heading in the right direction, the Business Day Value column is exactly what i had in mind.
Regarding your two questions, I was referring to your Switch statement where you want to account for the case where you want a negative value as a result, in that case you need to compare the two dates to see which is smaller than the other and account for that. The CALCULATE simply filters the calendar table to contain only the dates between your cutoffs and then sums up the working dates. See below for an example, you may need to adjust somewhat, I haven't tested this but it should give you the right idea.
Day Count of Drop = IF('KPI Dashboard AD'[Campaign Creation Date]<'KPI Dashboard AD'[Start Date],
CALCULATE(Sum('Date'[Business Day Value]),
FILTER('Date', 'Date'[DateColumn] >= 'KPI Dashboard AD'[Campaign Creation Date] &&
'Date'[DateColumn] < 'KPI Dashboard AD'[Start Date])), CALCULATE(Sum('Date'[Business Day Value]),
FILTER('Date', 'Date'[DateColumn] <= 'KPI Dashboard AD'[Campaign Creation Date] &&
'Date'[DateColumn] > 'KPI Dashboard AD'[Start Date])) * -1 )- erik_tarnvik8 years ago
Solution Specialist
I should mention also that you could use DATESBETWEEN function with your calendar table for a more elegant solution but I figured my example would be easier to follow. See