Forum Discussion
Excluding/Filtering by Certain times
- 10 years ago
I have two columns, "dateIN" and "dateDelivered" that are date/time types. I need to calculate the number of hours between the two, but only counting business hours (9am-6pm)
Using the formula below(just change "MyTable" to your table name) to create a calculate column should meet your requirement:
TotalWorkHour = VAR Days = DATEDIFF ( MyTable[dateIN], MyTable[dateDelivered], DAY ) VAR InHour = HOUR ( MyTable[dateIN] ) VAR DeliveredHour = HOUR ( MyTable[dateDelivered] ) RETURN IF ( InHour < 9, 9, IF ( InHour > 18, 0, 18 - InHour ) ) + IF ( DeliveredHour < 9, 0, IF ( DeliveredHour > 18, 9, DeliveredHour - 9 ) ) + ( Days - 1 ) * 9Regards
- 10 years ago
Please refer to the formula below:
TotalWorkHour = VAR Days = DATEDIFF ( MyTable[dateIN], MyTable[dateDelivered], DAY ) VAR InHour = HOUR ( MyTable[dateIN] ) + MINUTE(MyTable[dateIN])/60 VAR DeliveredHour = HOUR ( MyTable[dateDelivered] ) + MINUTE(MyTable[dateDelivered])/60 RETURN IF ( InHour < 9, 9, IF ( InHour > 18, 0, 18 - InHour ) ) + IF ( DeliveredHour < 9, 0, IF ( DeliveredHour > 18, 9, DeliveredHour - 9 ) ) + ( Days - 1 ) * 9Regards
I got hung up on step 5. Ctrl+ click doesn't select multiple columns for me. I also don't see a date dropdown for "Subtract Days"
To select multiple columns, be sure you are clicking the column header, instead of a value in the column. If you click one column header, the whole column should be highlighted. Ctrl+clicking the second column should now show both highlighted.
Subtract Days will be grayed out without two columns selected. If it's not there at all, I recommend installing the latest version, as I'm assuming it was added since then. I'm on the July release currently and have it there.