Explanation

The goal in this example is to calculate a cost of living (COLA) adjustment for each of the eleven years shown, starting on the second year. The actual adjustment percentage is entered in cell F6, which is the named range cola . Each year, the adjustment should be applied to the previous base amount in column C, starting with the base amount in cell C5.

The formula in cell C6, copied down is:

=C5+(C5*cola)

With 30,000 in C5 as shown, the formula is solved like this:

=C5+(C5*cola)
=30000+(30000*0.03)
=30000+900
=30900

As the formula is copied down the table, the relative reference C5 changes at each row, while the named range cola (F6) behaves like an absolute reference and does not change. The result on each new row is the previous year’s base plus the adjustment.

Total adjustments

To calculate the total of all adjustments, the formula in F7 is:

=SUM(C5:C15-C5)

This is an array formula , and must be entered with control+shift+enter, except in Excel 365 . The result is the total of all adjustments made since year 1.

Alternative layout

The screen below shows an alternative layout that breaks out the adjustment amount separately, and allows a different rate of adjustment for each year.

COLA calculation alternative layout - 1

The formula in N5, copied down, calculates the adjustment:

=M5*L5

The formula in M6, copied down, calculates a new base for year:

=M5+N5

Explanation

In this example, the goal is to count the maximum number of consecutive monthly orders. That is, we want to count consecutive monthly orders greater than zero. This is a tricky formula to understand, so buckle up!

They key to the formula is knowing that the FREQUENCY function gathers numbers into “bins” in a particular way. Each bin represents an upper limit, and contains a count of all numbers in the data set that are less than or equal to the upper limit, and greater than the previous bin number. The trick then is to create the data_array argument using the condition you want to test for (order count greater than zero in this case), and the bins_array using the opposite condition.

To create the data_array bin we use the following code:

IF(C5:H5>0,COLUMN(C5:H5))

Here, we use the IF function to test the order count in each month to see if it’s greater than zero. If so, IF returns the column number using the COLUMN function . The result from IF is an array like this:

{3,FALSE,FALSE,6,7,8}

Notice that only columns where order count > 0 make it into this array. Those columns where the count is zero become FALSE.

The bins_array is generated with this snippet:

IF(C5:H5=0,COLUMN(C5:H5))

Here the IF function is used again to test the order count in each column, but this time the logic is reversed. Only column numbers where the count is zero make it into the array returned by IF, which looks like this:

{FALSE,4,5,FALSE,FALSE,FALSE}

Per standard FREQUENCY behavior, the numbers in the bins_array become the functional bins that tally non-zero orders. Months where orders are greater than zero are translated to FALSE and don’t collect any numbers from the data array, since FALSE values are ignored. The result is that the surviving bins count the number of consecutive non-zero orders up to that point, but excluding those previously counted. This all works because of the incrementing nature of rows and columns – you can be certain that the “next” number is always greater than the previous number.

With the data array and bin arrays as shown above, FREQUENCY returns a count per bin in an array like this:

{1;0;3}

The FREQUENCY function always returns an array with one more item than bins in the bins_array . This is by design, to catch any values greater than the largest value in the bins_array . This array is returned directly to the MAX function , with returns the largest number in the array:

=MAX({1;0;3}) // returns 3

Other consecutive values

To count consecutive occurrences of other values, just adjust the logic as needed following the same pattern: the first condition tests for the thing you want to count, the second condition tests for the opposite.