title: Can I compare values in the same column in adjacent rows in PowerPivot?
body: <p>I have a PowerPivot table for which I need to be able to determine how long an item was in an Error state. My data set looks something like this:</p>
  
  <p><img src="https://i.stack.imgur.com/93hIR.png" alt="enter image description here"></p>
  
  <p>What I need to be able to do is to look at the values in the ID and State columns, and see if the value in the previous row is ERROR in the State column, and the same in the ID column. If it is, I then need to calculate the difference between the Changed Date values in those two rows.</p>
  
  <p>So, for example, when I got to row 4, I would see that the value in the State column for Row 3, the previous row, is ERROR, and that the value in the ID column in the previous row is the same as the current row, so I would then calculate the difference between the Changed Date values in Row 3 and Row 4 (I don't care about the values in any of the other columns for this particular requirement).</p>
  
  <p>Is there a way to do this in PowerPivot? I've done a fair amount of Internet searching, and it looks like if it can be done, it would use the EARLIER or EARLIEST DAX functions, but I can't find anything that tells me how, or even if, this can be done.</p>
  
  <p>Thanks.</p>