title: Excel - calculating durations of time data spread across multiple rows
body: <p>I have a spreadsheet with a dataset of a number of transactions, each of which is composed of substeps, each of which has the time that it occurred.  There can be a variable number and order of steps.</p>
  
  <p>I'd like to find the duration of each transaction.  If I can do this in Excel then great, as it's already in that format.  If there isn't a straight-forward way to do this in Excel, I'll load it into a database and do the analysis with SQL.  If there is an Excel way round this it'll save a few hours setup though :)</p>
  
  <p>A simplified example of my data is as follows:</p>
  
  <p>TransID, Substep, Time<br>
  1, step A, 15:00:00<br>
  1, step B, 15:01:00<br>
  1, step C, 15:02:00<br>
  2, step B, 15:03:00<br>
  2, step C, 15:04:00<br>
  2, step E, 15:05:00<br>
  2, step F, 15:06:00<br>
  3, step C, 15:07:00<br>
  3, step D, 15:08:00<br>
  etc.</p>
  
  <p>I'd like to produce a result set as follows:</p>
  
  <p>TransID, Duration<br>
  1, 00:02:00<br>
  2, 00:03:00<br>
  3, 00:01:00<br>
  etc.</p>
  
  <p>My initial try was with an extra column with a formula subtracting end time from start time, but without a repeating number of steps, or the same start and end steps I'm having difficulty seeing how this formula would work.</p>
  
  <p>I've also tried creating a pivot table based on this data with ID as the rows and Time as the data.  I can change the field settings on the time data to return grouped values such as count or max, but am struggling to see how this can be setup to show max(time) - min(time) for each ID, hence why I'm thinking about heading to SQL.  If anyone can point out anything obvious I'm missing though, I'd be very grateful.</p>
  
  <p>As suggested by Hobbo, I've now used a pivot table with TransID as the rows and twice added Time as the data.  After setting the field settings on the Time to Max on the first and Min on the second, a formula can be added just outside the pivot table to calculate the differences.  One thing I'd been overlooking here is that the same value can be added to the data section more than once!</p>
  
  <p>A follow-on problem was that the formula I add is of the form =GETPIVOTDATA("Max of Time",$A$4,"ID",1)-GETPIVOTDATA("Min of Time",$A$4,"ID",1), whici doesn't then increment when copying and pasting.  Solutions to this are to either use the pivot table toolbar to turn off GETPIVOTDATA formulae, or rather than clicking on the pivot table when selecting cells in the formula, type the cell references instead (e.g. =H4-G4)</p>