Forum Discussion
Automated time intervals between StartTime and EndTime in Power Query
- 6 years ago
Hi StephenK ,
Try this:
1. Add a custom column.
= if [Provider] = "Provider A" then List.Times([StartTime], Duration.TotalMinutes([EndTime]-[StartTime])/15+1,#duration(0,0,15,0)) else if[Provider] = "Provider B" then List.Times([StartTime], Duration.TotalMinutes([EndTime]-[StartTime])/10+1,#duration(0,0,10,0)) else if[Provider] = "Provider C" then List.Times([StartTime], Duration.TotalMinutes([EndTime]-[StartTime])/15+1,#duration(0,0,15,0)) else if[Provider] = "Provider D" then List.Times([StartTime], Duration.TotalMinutes([EndTime]-[StartTime])/10+1,#duration(0,0,10,0)) else if[Provider] = "Provider E" then List.Times([StartTime], Duration.TotalMinutes([EndTime]-[StartTime])/10+1,#duration(0,0,10,0)) else null2. Expand to new rows.
Then, you can get this:
For more details, please check the attached PBIX file.
Best Regards,
Icey
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Icey This is great! Thank you so much. I'm gonna throw a curveball now--so with my current clunky formula, it stops the interval at the last 15 minutes before the EndTime so that the EndTime does not get counted in the interval. Example:
| Date | Provider | SlotTime | StartTime | EndTime |
| 2/27/2020 | Provider A | 8:00 AM | 8:00 AM | 8:45 AM |
| 2/27/2020 | Provider A | 8:15 AM | 8:00 AM | 8:45 AM |
| 2/27/2020 | Provider A | 8:30 AM | 8:00 AM | 8:45 AM |
The idea is that 8:30 is the last 15 minute slot and the schedule closes at 8:45. The new formula is counting the 8:45 slot as well.
| Date | Provider | SlotTime | StartTime | EndTime |
| 2/27/2020 | Provider A | 8:00 AM | 8:00 AM | 8:45 AM |
| 2/27/2020 | Provider A | 8:15 AM | 8:00 AM | 8:45 AM |
| 2/27/2020 | Provider A | 8:30 AM | 8:00 AM | 8:45 AM |
| 2/27/2020 | Provider A | 8:45 AM | 8:00 AM | 8:45 AM |
How would you modify the formula to stop one interval before the EndTime?
Hi StephenK ,
In the original formula, there is a "+1", just delete it.
Duration.TotalMinutes (...) / 15 + 1
So, try this:
= if [Provider] = "Provider A" then List.Times([StartTime], Duration.TotalMinutes([EndTime]-[StartTime])/15,#duration(0,0,15,0))
else if[Provider] = "Provider B" then List.Times([StartTime], Duration.TotalMinutes([EndTime]-[StartTime])/10,#duration(0,0,10,0))
else if[Provider] = "Provider C" then List.Times([StartTime], Duration.TotalMinutes([EndTime]-[StartTime])/15,#duration(0,0,15,0))
else if[Provider] = "Provider D" then List.Times([StartTime], Duration.TotalMinutes([EndTime]-[StartTime])/10,#duration(0,0,10,0))
else if[Provider] = "Provider E" then List.Times([StartTime], Duration.TotalMinutes([EndTime]-[StartTime])/10,#duration(0,0,10,0))
else null
Best Regards,
Icey
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.