Split a start and end date into set durations

th081

Board Regular
Joined
Mar 26, 2006
Messages
98
Office Version
  1. 365
Platform
  1. Windows
Hi,

I have a table in with a start date and time eg 01/12/20 04:05 and a end date and time 03/12/20 12:07 . These are in separate columns.

I would like to split the duration into 4 hour chunks starting at 01/12/20 00:00 to 04:00 then 04:00 to 08:00 etc. So for the date time in question it would have zero value for 00:00 to 04:00, 235 mins for 04:00 to 08:00 etc. I will then apply a charge per minute to the value shown, the charge per minute is different in each chunk hence the need to split.

Can anyone advise if Power Query can do this or if I would be better using VBA.
 

Excel Facts

Can you sort left to right?
To sort left-to-right, use the Sort dialog box. Click Options. Choose "Sort left to right"
The data table:

Start Date and TimeEnd Date and Time
02/11/2020 04:0502/11/2020 16:07
02/11/2020 00:2502/11/2020 20:45
01/11/2020 01:3001/11/2020 02:45

reference table to decide on start/end date and duration of slice

Start Date and Time:
01/11/2020 00:00​
Slices (hours)4 hours
End Date and Time
03/11/2020 04:00​


Results - from the third column it represents 4 hours as per the second table.

Mins in sliceMins in sliceMins in sliceMins in sliceMins in sliceMins in sliceMins in sliceMins in sliceMins in sliceMins in sliceMins in sliceMins in sliceMins in sliceMins in slice
Start Date and TimeEnd Date and Time
01/11/2020 00:00​
01/11/2020 04:00​
01/11/2020 08:00​
01/11/2020 12:00​
01/11/2020 16:00​
01/11/2020 20:00​
02/11/2020 00:00​
02/11/2020 04:00​
02/11/2020 08:00​
02/11/2020 12:00​
02/11/2020 16:00​
02/11/2020 20:00​
03/11/2020 00:00​
03/11/2020 04:00​
02/11/2020 04:0502/11/2020 16:0702352402407000000000
02/11/2020 00:2502/11/2020 20:452152402402402402402402402402402404500
01/11/2020 01:3001/11/2020 02:45750000000000000
 
Upvote 0
Hi Sandy666,

yes i did but this is a work machine and i dont think it will allow me to download addins etc
 
Upvote 0
Book2.xlsx
CDEFGHIJKLMNOPQR
4Start Date and TimeEnd Date and Time01/11/2020 00:00
502/11/2020 04:0502/11/2020 16:07Slices (hours)4 hours
602/11/2020 00:2502/11/2020 20:45End Date and Time03/11/2020 04:00
701/11/2020 01:3001/11/2020 02:45
8
9
10Results
11Mins in sliceMins in sliceMins in sliceMins in sliceMins in sliceMins in sliceMins in sliceMins in sliceMins in sliceMins in sliceMins in sliceMins in sliceMins in sliceMins in slice
12Start Date and TimeEnd Date and Time01/11/2020 00:0001/11/2020 04:0001/11/2020 08:0001/11/2020 12:0001/11/2020 16:0001/11/2020 20:0002/11/2020 00:0002/11/2020 04:0002/11/2020 08:0002/11/2020 12:0002/11/2020 16:0002/11/2020 20:0003/11/2020 00:0003/11/2020 04:00
1302/11/2020 04:0502/11/2020 16:0702352402407000000000
1402/11/2020 00:2502/11/2020 20:452152402402402402402402402402402404500
1501/11/2020 01:3001/11/2020 02:45750000000000000
Sheet3
Cell Formulas
RangeFormula
F12:R12F12=(4/24)+E12
 
Upvote 0
imho, vba would be better for you (or even formula) and if you decide for vba then ask moderator to move this thread to the proper forum
 
Upvote 0
thank you, i will be able to do the VBA myself however i wanted to see if it could be done by Power Query as i have only just started using it and have very limited knowledge in the area.
 
Upvote 0

Forum statistics

Threads
1,223,761
Messages
6,174,342
Members
452,555
Latest member
colc007

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top