RankIf without Arrays? (Excel 2010)

Roghaltz

New Member
Joined
Nov 26, 2015
Messages
26
Hello All,
I've been using the RankIf functionality (based on SUMPRODUCT)that members have posted on here for a while now and it's great. However, I've run into a problem with a large simulation/optimization problem with this method. Every time it tries a new set of inputs it has to recalculate the spreadsheet which takes 10-15 seconds and sometimes crashes Excel after 5-10 minutes. Even when it doesn't crash at 10-15 seconds per iteration the time needed to run 10,000 iterations is too large.

I am looking for a RankIf type function that does not use array formulas and thus will run faster (when I use the regular RANK function on a subset of the spreadsheet (say 200 rows) it works very fast). I have 50,000 rows in the full model so I don't want to manually enter the RANK function every ten or so rows and adjust the cell references.

Here is the basic layout of the spreadsheet:
SalesmanProductPredOutPutInput1InputX
a1Apples5.1
a2Apples4.7
......
a10Apples8.3
b1Bananas7.3
b2Bananas6.3
......
b8Bananas9.5
b9Bananas8.5

<tbody>
</tbody>

The column PredOutput is a function of about 10 other columns (input 1...input X) that the optimization applies different weights to. I am looking to rank the PredOutput variable within each product. The rank of PredOutput will change after each simulation iteration. As I said the sumproduct formula works fine in general, but the array causes it to take too long to do a simulation.

I was hoping that since the individual products are grouped to together there might be a way to rank PredOutput without arrays (that is Apples begins in row 2 and ends in row 11, Bananas begins in row 12 and ends in row 20, etc.) There are thousands of products and each one has between 8 and 14 salesmen.

Happy to clarify this further as needed.

Thanks in advance.
Roghaltz
 

Excel Facts

Add Bullets to Range
Select range. Press Ctrl+1. On Number tab, choose Custom. Type Alt+7 then space then @ sign (using 7 on numeric keypad)
You can try with helper columns for the start and end indexes of the product on each line.
E.g. start indices in column Y: Y2 =if(B2=B1),Y1,ROW())
end indices in column Z: Z2 =IF(B2=B3),Z3,ROW())
So on each "Apples" row, you get 2 in Y and 11 in Z.

Now you can determine the rank as =RANK($C2,INDEX($C:$C,Y2):INDEX($C:$C,Z2))

Drawback of this solution: if you add/delete any rows, you need to copy the formulas in Y2 and Z2 down again to correct reference errors.
 
Upvote 0
Thanks Marcel. I will give it a try this weekend. That's the kind of solution I was hoping for.

Roghaltz
 
Upvote 0
Here's an alternative which does not require helper columns.
Excel 2010
ABCDEF
1SalesmanProductPredOutPutInput1InputXRanking
2a1Apples5.12
3a2Apples4.73
4a10Apples8.31
5b1Bananas7.33
6b2Bananas6.34
7b8Bananas9.51
8b9Bananas8.52
9a1Cantaloupe1.14
10a2Cantaloupe2.72
11a3Cantaloupe9.31
12a7Cantaloupe2.13

<colgroup><col style="width: 25pxpx"><col><col><col><col><col><col></colgroup><thead>
</thead><tbody>
</tbody>
Sheet6

Worksheet Formulas
CellFormula
F2=COUNTIFS($B$2:$B$12,B2,$C$2:$C$12,">"&C2)+1

<thead>
</thead><tbody>
</tbody>

<tbody>
</tbody>


Put the formula in F2 and copy down. I can't speak to the performance of it, but it should be quick.
 
Upvote 0

Forum statistics

Threads
1,215,465
Messages
6,124,982
Members
449,201
Latest member
Lunzwe73

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top