With Power Query
Load your table to the PQ Editor and add index columns
let
Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Time", type datetime}}),
#"Extracted Time" = Table.TransformColumns(#"Changed Type",{{"Time", DateTime.Time, type time}}),
#"Added Index" = Table.AddIndexColumn(#"Extracted Time", "Index", 0, 1, Int64.Type),
#"Added Index1" = Table.AddIndexColumn(#"Added Index", "Index.1", 1, 1, Int64.Type)
in
#"Added Index1"
Merge the table onto itself and compare times
let
Source = Table.NestedJoin(Table1, {"Index"}, Table1, {"Index.1"}, "Table1", JoinKind.LeftOuter),
#"Expanded Table1" = Table.ExpandTableColumn(Source, "Table1", {"Time"}, {"Table1.Time"}),
#"Sorted Rows" = Table.Sort(#"Expanded Table1",{{"Index", Order.Ascending}}),
#"Inserted Time Subtraction" = Table.AddColumn(#"Sorted Rows", "Subtraction", each [Time] - [Table1.Time], type duration),
#"Removed Other Columns" = Table.SelectColumns(#"Inserted Time Subtraction",{"Time", "Subtraction"})
in
#"Removed Other Columns"
Power Query is a free AddIn for Excel 2010 and 2013, and is built-in functionality from Excel 2016 onwards (where it is referred to as "Get & Transform Data").
It is a powerful yet simple way of getting, changing and using data from a broad variety of sources, creating steps which may be easily repeated and refreshed. I strongly recommend learning how to use Power Query - it's among the most powerful functionalities of Excel.
- Follow this link to learn how to install Power Query in Excel 2010 / 2013.
- Follow this link for an introduction to Power Query functionality.
- Follow this link for a video which demonstrates how to use Power Query code provided.
Bookmarks