In essence we're simply using a standard COUNTIF and a COUNTIF as you know works along the lines of:
In our case our formula (for D2) looks like
So you can see (by means of colour coding) that we use 2 INDEX functions to create the range and a subsequent IF in conjunction with & and < operator to create the criteria
(the last bit in Italics which sits outside of the COUNTIF is to ensure we're displaying only "periodic" movement - inappropriate term here in truth but one that epitomises the general principle)
So - range - in more detail...
You can see the INDEX calls are separated by a colon indicating we're using INDEX in this context to create range references - this may be different to how you've seen it used before ?
INDEX is a pretty flexible formula, eg:
could be used to return contents of A10 or
could be used to create a range A10:A20
make sense ?
In your case the start row & end row for the range is determined by the rolling sum of the values in Column B, for ex. B2 = 51 ... this figure states we should look only at the first 51 rows of data in the table... we know first row of data is row 2.
So to establish starting cell we have:
which says column is A and row is to be 2 + sum of prior values (ie excluding current row) in B which for row 2 will be 0 given B1 is non-numeric
To establish end row we have:
which says column is A and row is to be 1 + sum of all values in B up to and including the current row which for row 2 will be 52 (1+51)
Thus we end up in essence with a range that says
When we move to the next row down in our records the start row & end row will update accordingly, eg:
So our start range for the COUNTIF in row 3 of our results table will be:
And end row
Does that make sense ?
The criteria for the COUNTIF we set to be the value in row 1 in the column to the right of the cell containing the formula (ie less than next boundary), however, when it comes to the last column we have a problem given there is no limit in the next cell - to account for this we use the IF
so we say if the value in row 1 of the column to the right is non-numeric use 5000000 else use the value in row 1 of the column to the right.
to get this into a readable string we concatenate the "<" operator with this value by means of & ....
Obviously this means in each column we're counting how many records are less than the limit ... but this will obviously include values that may be included in prior boundaries so we need to subtract the prior totals from the COUNTIF total
Bookmarks