title: Averageif and Offset Function in Excel to get a Rolling Average
body: <p>I have a bunch of sequential rows and I'm trying to average the last 90 based on a criteria. The average needs to be in a single cell, rather than a column that calculates a running average. I figured out how to calculate an average for the last 90 rows, but I am not able to correctly add the if function to meet the criteria prior to averaging. </p>
  
  <p>Data:</p>
  
  <pre><code>sale type (b)        Data(c)      Rownumber (E) 
  a                     45             1
  b                     35             2 
  c                     36             3 
  c                     56             93
  </code></pre>
  
  <p>Here is the average function that's working correctly <code>AVERAGE(OFFSET(E2,COUNTA(E:E)-1,-2,-90)).</code></p>
  
  <p>Here is the <code>AVERAGEIF</code> function that I'm trying to run that is giving incorrect data: </p>
  
  <pre><code>=AVERAGEIF(B:B,I15,OFFSET(E2,COUNTA(E:E)-1,-2,-90))
  </code></pre>
  
  <p><code>I15</code> cell in this case, is the sale type that I am trying to match. </p>
  
  <p>Thanks in advance for the help!</p>