title: How to subtract dates on different rows in POWER BI
body: <p>I have a table that looks like this:</p>
  
  <p><a href="https://i.stack.imgur.com/TqdQx.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/TqdQx.png" alt="enter image description here"></a></p>
  
  <p>Bear with me this is going to get a little confusing;</p>
  
  <p>I want to get the values in the desired column. The calculation is:
  <strong><em>StartTime-(previous row)Endtime</em></strong>. So row 2 (Starttime) minus row 1 Endtime would be 17:04:48 minus 17:04:31 (=17sec). However I want to <strong>exclude</strong> rows where <strong>CustAgentFl = 0 AND Transferflag = 0</strong> before doing the date subtract calculation. Also, if Starttime- Endtime is &lt;0 then just 0.</p>
  
  <p>The rows are all grouped by the same NID, so of course the DAX query will need to group by the NID.</p>