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.
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
)
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