Forum Discussion
Counting last N days with data, excluding weekends
- 6 years ago
Hi Anonymous ,
Try this:
Data Availability Ratio = VAR num_of_selected_days = [Number of Days Value Value] VAR date1 = LASTDATE ( 'Calendar'[Date] ) VAR date2 = date1 - num_of_selected_days VAR WeekendDays = CALCULATE ( COUNT ( 'Calendar'[DayType] ), FILTER ( ALLSELECTED ( 'Calendar' ), 'Calendar'[DayType] = "Weekend" && 'Calendar'[Date] > date2 && 'Calendar'[Date] <= date1 ) ) VAR num_ = IF ( MOD ( WeekendDays, 2 ) = 0, WeekendDays , WeekendDays+ 1 ) VAR date3 = IF ( WeekendDays >= 1, date2 - num_, date2 ) VAR num_of_days_with_data = CALCULATE ( SUM ( Futures[Data Availability] ), FILTER ( ALL ( 'Calendar' ), 'Calendar'[Date] > date3 && 'Calendar'[Date] <= date1 && 'Calendar'[DayType] = "Weekday" ) ) VAR Ratio = DIVIDE ( num_of_days_with_data, num_of_selected_days ) RETURN IF ( MAX ( 'Calendar'[DayType] ) = "Weekday", CALCULATE ( IF ( ISBLANK ( ratio ), 0, Ratio ), FILTER ( 'Calendar', 'Calendar'[DayType] = "Weekday" ) ) )BTW, .pbix file attached.
Best Regards,
Icey
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Anonymous , refer to this file, It has an example of working days between dates.
Check 2nd Page
https://www.dropbox.com/s/y47ah38sr157l7t/Order_delivery_date_diff.pbix?dl=0
I think this is the count of workdays in the measure below, but in my scenario I'm trying to count a different column that has 0 or 1 (if we have data for the day 1, if not 0) and as an addition I only want to take workdays into account, so if my parameter is 3 (looking at 3 last days) and I am looking at a row, where the date is a Monday, it should consider the Monday and then the Thursday & Friday before that, ignoring the 2 weekend days.