Returning highest 5 numbers in range with conditions

onthegreen03

Board Regular
Joined
Jun 30, 2016
Messages
148
Office Version
  1. 365
Platform
  1. Windows
Hi. I posted earlier about this issue, thought I had it licked but alas did not. I pasted a picture below to help explain the issue I am having. I have a table with the top 5 and bottom 5 locations for a certain account. For the top 5 I am using a SMALL formula which looks at the specified range (using RANK formula) and returns 1 through 5, so no issues with that chart. The problem is the bottom 5 chart. When the parent account has more than 10 locations a LARGE formula will and does work. But when the total locations are between 6 and 9 some of the numbers repeat. In the example below I need to write a formula that looks at the range of numbers (in this case 1-8) and only return 6-8. If more information is needed to solve this let me know and I will include. This has stumped me all day. Thank you!

1635542302046.png
 

Excel Facts

How to total the visible cells?
From the first blank cell below a filtered data set, press Alt+=. Instead of SUM, you will get SUBTOTAL(9,)
Try:

Book1
ABCDEFGH
1CityStateZipRatingTop 5 Locations:
2AustinTX787583CityStateZip
3HoustonTX770561HoustonTX77056
4San AntonioTX782292San AntonioTX78229
5LafayetteLA705088AustinTX78758
6PflugervilleTX786605New OrleansLA70115
7New OrleansLA701154PflugervilleTX78660
8AustinTX787326
9AustinTX787387Bottom 5 Locations:
10CityStateZip
11LafayetteLA70508
12AustinTX78738
13AustinTX78732
14
Sheet6
Cell Formulas
RangeFormula
F3:H7F3=INDEX(SORTBY(A2:C10,D2:D10),SEQUENCE(5),{1,2,3})
F11:H13F11=INDEX(SORTBY(A2:C10,D2:D10,-1),SEQUENCE(MIN(5,COUNTA(A2:A10)-5)),{1,2,3})
Dynamic array formulas.
 
Upvote 0
Hi Eric. Thank you for the suggestion, this is exactly what I needed. What if I wanted to return just the resulting RANK numbers (In your example the top 5 in cells F3:F7 and bottom 5 in cells F11:F15)? In your example I would want to return numbers 1-5 in cells F3:F7 and 6,7, and 8 in cells F11:F13, while cells F14:F15 would be blank. Below is the actual table that I am using. The RANK formula is sitting in cells A8:A65. Depending on the number of locations that range will obviously change (in this example there are 8 locations). What I am looking for is a formula that returns the top 5 numbers (1 through 5 in this example), and the bottom 5 (6-8 in this example). There are times when the account only has 3 locations, so in that case I'd want to return 1, 2 and 3, while the bottom 5 would be blank. In other cases the account may have 25 locations, so I'd want to return 1-5 (top) and 21-25 (bottom). Let me know if you have any suggestions to accomplish this. Thanks again!

1635775761668.png
 
Upvote 0
How about:

Book1
ABCDEFGHIJK
1Top 5 Locations:
2RankCityStateZip
31HoustonTX77056
42San AntonioTX78229
53AustinTX78758
64New OrleansLA70115
7RatingZipCityState5PflugervilleTX78660
83Yes78758AustinTX
91Yes77056HoustonTXBottom 5 Locations:
102Yes78229San AntonioTXRankCityStateZip
118Yes70508LafayetteLA8LafayetteLA70508
125Yes78660PflugervilleTX7AustinTX78738
134Yes70115New OrleansLA6AustinTX78732
146Yes78732AustinTX
157Yes78738AustinTX
16#N/A#N/A#N/A
17#N/A#N/A#N/A
18#N/A#N/A#N/A
19#N/A#N/A#N/A
20#N/A#N/A#N/A
Sheet6
Cell Formulas
RangeFormula
H3:K7H3=INDEX(SORT(FILTER(A8:F20,IFERROR(B8:B20="Yes",0))),SEQUENCE(MIN(5,COUNTIF(B8:B20,"Yes"))),{1,5,6,4})
H11:K13H11=IFERROR(INDEX(SORT(FILTER(A8:F20,IFERROR(B8:B20="Yes",0)),,-1),SEQUENCE(MIN(5,COUNTIF(B8:B20,"Yes")-5)),{1,5,6,4}),"")
Dynamic array formulas.
 
Upvote 0
Solution
Amazing! Of course it worked and thank you. The only issue is this. In the results table I have the City name merged into 3 columns so the longer names fit correctly. Is there a way to edit the formulas so that the city populates columns I-J-K and the State in column L and zip in column M (based on your example above)? I had to unmerge those 3 columns to get the formula to work. If not, no big deal. I can just go back through my model and unmerge those City name cells and just readjust the column widths. Not ideal but I can do that if needed. So grateful for your help on this one Eric ... Thanks!!
 
Upvote 0
Merged cells usually pose a real problem with formulas. I can usually figure out a way to read from a merged cell, but as far as I know, these SPILL formulas won't SPILL into merged cells. You'd probably need to create separate formulas for each column. If you'd want to leave the source table alone, just make sure the ranges in the formula include the entire columns, and use the first column with the city as the output column (in the {1,5,6,4} array). But the output table pretty much has to be a single column. Just widen it so that the whole city name shows. I'd actually recommend unmerging your source table too, but that's your call.
 
Upvote 0
Will do, taking your advice as we speak. Thank you again ... the formula's work great!
 
Upvote 0

Forum statistics

Threads
1,214,376
Messages
6,119,172
Members
448,870
Latest member
max_pedreira

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