Extracting Data from Specific Data/Time range

Engineer1998

New Member
Joined
Nov 17, 2022
Messages
1
Office Version
  1. 365
Platform
  1. Windows
Hey guys, I have been trying to figure out how to take specific events and extract them during a specific date and time range. For example, if I want to sum the data a of specific event that happened from 7/17/2022 @ 6:00 AM to 7/17/2022 @ 6:00 PM. I would like to be able to just enter the date and time range I need and then excel tallies all those events in that time frame and extracts it from the event log. Like if i want to see how much time we spent on Pre_Job during 7/15/2022 @ 6:00 AM to 7/15/2022 @ 6:00 PM. I would like it to add up the total hours during that range.
Any help with this would be appreciated.

Start Date: 7/15/2022 Start Time: 6:00 AM End Date 7/15/2022 End Time: 6:00 PM

Pre Job: X hours During Job: X hours Open Well X hours ....ETC.
1668711288286.png
 

Excel Facts

Best way to learn Power Query?
Read M is for (Data) Monkey book by Ken Puls and Miguel Escobar. It is the complete guide to Power Query.
Create a table for your Start and End Times.
Book1
ABCD
1Filter
2Start DateStart TimeEnd DateEnd Time
307/08/202207:00:00 AM07/16/202206:00:00 PM
Sheet1


That's a Table named Filter. Pull it into Power Query and fix the Data Types.
Power Query:
let
    Source = Excel.CurrentWorkbook(){[Name="Filter"]}[Content],
    ChangedType = Table.TransformColumnTypes(Source,{{"Start Date", type date}, {"Start Time", type time}, {"End Date", type date}, {"End Time", type time}})
in
    ChangedType
Load Filter ONLY as a Connection.
Now assume this is your data in a Table named Data. (clever naming scheme, hey?)
Book1
FG
1Data
2DateTime
307/02/202211:34:43 AM
407/02/202210:41:14 PM
507/03/202202:20:48 PM
607/03/202205:15:15 PM
707/04/202203:00:41 PM
807/08/202201:23:08 AM
907/08/202206:20:14 AM
1007/08/202207:11:13 AM
1107/10/202208:58:49 PM
1207/12/202212:36:15 AM
1307/13/202211:36:36 PM
1407/14/202202:54:51 AM
1507/14/202212:54:08 PM
1607/16/202208:13:44 AM
1707/17/202202:47:31 AM
1807/17/202201:18:56 PM
1907/18/202207:36:55 PM
2007/21/202212:16:39 PM
2107/21/202204:01:42 PM
2207/21/202205:55:10 PM
2307/23/202203:05:58 AM
2407/23/202210:59:21 AM
2507/24/202205:28:12 PM
2607/24/202210:31:23 PM
2707/25/202209:12:01 PM
2807/28/202201:18:16 AM
2907/28/202202:22:57 PM
3007/29/202210:36:33 PM
3107/30/202203:16:54 PM
3207/30/202204:44:33 PM
Sheet1


Pull that into Power Query. Rename the Query FilteredData and transform it like this.
Power Query:
let
    Source = Excel.CurrentWorkbook(){[Name="Data"]}[Content],
    ChangedType = Table.TransformColumnTypes(Source,{{"Date", type date}, {"Time", type time}}),
    FilteredDate = Table.SelectRows(ChangedType, each [Date] >= Filter[Start Date]{0} and [Date] <= Filter[End Date]{0} ),
    FilteredTime = Table.SelectRows(FilteredDate, each [Time] >= Filter[Start Time]{0} and [Time] <= Filter[End Time]{0})
in
    FilteredTime

And load the table to a Worksheet.
Book1
IJ
1FilteredData
2DateTime
307/08/202207:11:13 AM
407/14/202212:54:08 PM
507/16/202208:13:44 AM
Sheet1


Now, whatever Start and End values you enter into the Filter table will be used on the next Refresh All to update the FilteredData table.

Sorry I didn't use your Start and End info, and would have used your table if it had been entered using XL2BB, but I think you'll get it, and it's a simpler to grasp.
 
Upvote 0

Forum statistics

Threads
1,215,530
Messages
6,125,347
Members
449,220
Latest member
Edwin_SVRZ

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