Explanation

This formula first generates a rank value using an expression based on COUNTIF:

=COUNTIF(data,"<="&B5)

which is explained in more detail here . If the data contains all text values, or all numeric values, the rank will be correct. However, if the data includes both text and numbers, we need to “shift” the rank of all text values to account for the numeric values. This is done with the second part of the formula here:

+(COUNT(data)*ISTEXT(B7))

Here, we use the COUNT function to get a count of numeric values in the data, then multiply the result by the logical result of ISTEXT, which tests if the value is text and returns either TRUE or FALSE. This effectively cancels out the COUNT result when we are working with a number in the current row.

Handling duplicates

If data contains duplicates, the formula can be altered as shown below to assign a sequential rank to values that appear more than once:

=COUNTIF(data,"<"&B5)+(COUNT(data)*ISTEXT(B5))+COUNTIF($B$5:B5,B5)

This version adjusts the logic of the initial COUNTIF function, and adds another COUNTIF with an expanding reference to increment duplicates.

Display sorted values

To retrieve and display values sorted values in alphabetical order using the calculated rank value, E5 contains the following INDEX and MATCH formula :

=INDEX(data,MATCH(ROWS($E$5:E5),rank,0))

where “data” is the named range B5:B13, and “rank” is the named range C5:C13.

For more information about how this formula works, see the example here .

Dealing with blanks

Empty cells will generate a rank of zero. Assuming you want to ignore empty cells, this works fine because the INDEX and MATCH formula above begins at 1. However, you will see #N/A errors at the end of sorted values, one for each empty cell. An easy way to handle this is to wrap the INDEX and MATCH formula in IFERROR like this:

=IFERROR(INDEX(data,MATCH(ROWS($E$5:E5),rank,0)),"")

Explanation

At the core, this is a simple formula that simply divides the total amount by the number of months given:

=amount/months

The trick is to “cancel out” this amount in months where it doesn’t apply.

To do this, we use this logical expression:

AND(E4>=start,E4<(start+months))

Here we use the AND function to test each month in row 4 to see if it’s both greater than or equal to the given start month, and less than the end month, calculated by adding the start month to total months.

AND will return TRUE only when both conditions are TRUE, and return FALSE in another other case. This effectively zeros out calculations in months that fall outside the range of interest. This works because during math operations, FALSE is coerced to zero, and TRUE is coerced to 1.

Without named ranges

The formula in the example shown uses three named ranges . Without these named ranges, the formula can be written like this:

=$C$4/$C$5*AND(E4>=$C$6,E4<($C$6+$C$5))