title: Excel calculate SUM of differences when cell addresses are not fixed
body: <p>In Excel I have a list of employees (see image) and I want to store their salary update history. For each salary update, I want to calculate the difference in their total salary. I'm unable to create a formula to calculate this and <code>SUM()</code> the updates per period for me.</p>
  
  <p>The image below demonstrates my spreadsheet and the desired salary update total (I did calculations manually, bet need a formula for this). In reality, there will be a few dozens of employees, so the requirement for the formula is to be dynamic and not contain manual "+" for each row.</p>
  
  <p><img src="https://i.stack.imgur.com/Lc9ZQ.jpg" alt="Example of my spreadsheet"></p>
  
  <p><strong>NOTE:</strong> For some people their salary can stay unchanged and there are not any values in some cells. It's the main challenge, since we have to find the value of the "previous salary" for an employee, because it's not necessary stored in the previous cell. Otherwise, I could have used a simple array formula, like:
  <strong>{=SUM(G3:G6-H3:H6)}</strong>. But unfortunately, it does not work in this case (there can be no value in the H column, so we have to find where it actually is).</p>
  
  <p>Also, the formula should work correctly with filtering: is some row is filtered out (person is inactive, see picture), this row/cell should be ignored.</p>
  
  <p>Can anybody help me with this formula that I'm struggling with?</p>