I have a barologger pressure time series that takes a reading every 15 minutes and a CT2X pressure time series that takes a measurement every 5 minutes. Unfortunately the time series is shifted and they don't align correctly. How can I filter my CT2X time series data so that it matches the time series of the barologger? How could I take an average of the three closest CT2X readings around the barologger time?
I have listed a picture "sample series columns" that ultimately shows what I wish to obtain.
I've tried the index-match tool in excel but I don't think I've used it correctly or if it can be done with this data.
Since you did not show averages as a part of what you expect for results, I chose to return a single closest value by aligning the values by
Barologger Date/Time
and each of the CT2X Date/Time
entries.I added a line and some information to the data you provided:
This can be accomplished using Power Query, available in Windows Excel 2010+ and Excel 365 (Windows or Mac)
To use Power Query
Data => Get&Transform => from Table/Range
Home => Advanced Editor
Applied Steps
to understand the algorithmM-Code
Edited to account for more rows in the last two columns than the first two
let
Source = Excel.CurrentWorkbook(){[Name="Table3"]}[Content],
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Barologger DateTime (24hr)", type datetime}, {"Barologger LEVEL (cm)", type number}, {"CT2X Date / Time (24 hour)", type datetime}, {"CT2X Pressure (psi)", type number}}),
//Split the tables
Barologger = Table.Buffer(Table.SelectColumns(#"Changed Type",List.Range(Table.ColumnNames(#"Changed Type"),0,2))),
CT2X = Table.Buffer(Table.SelectColumns(#"Changed Type", List.Skip(Table.ColumnNames(#"Changed Type"),2))),
//Find the matching rows
#"Matched CT2X" = Table.Buffer(Table.AddColumn(Barologger, "Match CT2X",(r)=>
let
//generate a list of differences between each of the times
difs = List.TransformMany(
CT2X[#"CT2X Date / Time (24 hour)"],
each {_ -r[#"Barologger DateTime (24hr)"]},
(a,b)=> Number.Abs(Number.From(b))),
//determine the row numbers with the matching min times, using 2 minutes (2/1440) as the threshold
pos = if List.Min(difs) < 2/1440
then List.PositionOf(difs,List.Min(difs))
else null
in pos)),
#"Matching CT2X" = Table.TransformColumns(#"Matched CT2X",{"Match CT2X",
each CT2X{_},type [#"CT2X Date / Time (24 hour)"=datetime, #"CT2X Pressure (psi)"=number]}),
#"Removed Errors" = Table.RemoveRowsWithErrors(#"Matching CT2X", {"Match CT2X"}),
#"Expanded Match CT2X" = Table.ExpandRecordColumn(#"Removed Errors", "Match CT2X", {"CT2X Date / Time (24 hour)", "CT2X Pressure (psi)"})
in
#"Expanded Match CT2X"
Either method gives the following results from the data I posted: