Surely you mean
=IF(D10 ="","",RANK(D10,$D$10:$D$28,0)+COUNTIF(D$10
$28,D10 )-1)
Note the range in countif
--
Kind regards,
Niek Otten
Microsoft MVP - Excel
| > <it messes up>
| >
| > What does that mean?
| >
| > Please give the values of the input cells and what exactly is the result of your formula
| >
|
| Hey Neik -
|
| Thanks for taking the time to look into this.
|
| I have a column that's supposed to be a serial ranking of another
| column's values. The RANK() function will have duplicate rank numbers
| for duplicate values, so the COUNTIF-1 is supposed to correct that.
| The final column you'll see here is a rank of the profit:
|
| Menu Item Price Cost Profit Rank
| A $12.95 $3.35 $9.60 4
| B $7.95 $2.00 $5.95 10
| C $17.95 $6.03 $11.92 1
| D $11.95 $4.00 $7.95 7
| E $14.95 $6.27 $8.68 5
| F $9.95 $4.00 $5.95 12
| G $16.95 $5.76 $11.19 3
| H $10.95 $3.50 $7.45 9
| I $14.95 $3.19 $11.76 2
| J $9.95 $2.00 $7.95 8
| K $11.95 $3.82 $8.13 6
| L $7.50 $2.50 $5.00 12
|
| The formula for the profit is simple subtraction:
| =IF(C10=0,"",B10-C10)
|
| So you see there are two '12's in the rank.
| This is the formula that I'm using:
| =IF(D10 ="","",RANK(D10,$D$10:$D$28,0)+COUNTIF(D$10:$D10,D10 )-1)
| This formula worked perfectly -- meaning a correct serial ranking of
| the values with no skips or duplications -- in other areas of the
| spreadsheet.
|
| ( note that actual values start on row 10 of the spreadsheet ).
|
| The COUNTIF is supposed to add an extra value for the number of
| instances of a value. Since you don't want to add the total count of
| $5.95s in the range, but only the count so far, the range of the
| COUNTIF must change throughout the column. So the final formula looks
| like this:
| =IF(D21 ="","",RANK(D21,$D$10:$D$28,0)+COUNTIF(D$10:$D21,D21 )-1)
|
| So, to troubleshoot, I split the formula into two columns, one for the
| RANK() function, and one for the COUNTIF function:
| Profit Count Rank Count+Rank
| $9.60 0 4 4
| $5.95 0 10 10
| $11.92 0 1 1
| $7.95 0 7 7
| $8.68 0 5 5
| $5.95 1 11 12
| $11.19 0 3 3
| $7.45 0 9 9
| $11.76 0 2 2
| $7.95 1 7 8
| $8.13 0 6 6
| $5.00 0 12 12
|
| The formula for the count column:
| =IF(D10 ="","",COUNTIF(D$10:$D10,D10 )-1
| rank:
| =RANK($D10,$D$10:$D$28)
| count+rank:
| =F10+G10
|
| So it looks like the problem is with the RANK function. The RANK has
| given the values of 10 and 11 to $5.95 -- yet it gave 7 to both $7.95.
| It seems to not work as advertised on the $5.95 values -- the
| documentation says that it should give the same rank value to the same
| values. I don't know if it's a decimal error, since the profit column
| is actually a formula, and perhaps at some precision both of the
| $5.95s are not the same.
|
| In any case, this is the best that I can re-create on a fresh
| spreadsheet. On my original spreadsheet, I do have a column that ranks
| correctly, but it refers two other columns for the complete formula,
| which is why I was looking for a merge formulas feature. I need to
| have the ranking in a single column, like in other areas of the
| spreadsheet.
|