filter Top 5 by 2 criterions

Omer_K

Board Regular
Joined
Apr 9, 2017
Messages
124
Office Version
  1. 365
Dear All,
I have a database divided by countries and letters,
(Each letter has a separate column),
I also have a data validaion list in cell J3 with all letters (from letter A to letter F),
And another cell data validaion list in cell J6 that also has all the letters (from letter A to letter F),
I would like to know how I can use by functions (not 365 functions like filter) to list all countries so that if I select a letter in cell J3 the list will show me all the countries with the highest score (eg 10 countries) in that letter and once I select another letter in cell J6 the list will narrow For the 5 countries on the existing list with the highest score in the second list (J6),
I hope i was clear...

חוברת2
BCDEFGHIJ
1ABCDEF
21.254.651.733.6846.47
34.56.265.14.321.231.57First ChooseB
43.65.31.076.213.861.01
56.752.381.424.016.075.25
65.873.172.896.642.921.47Second Choose
75.281.641.483.873.441.73
84.822.732.854.474.211.3
96.225.181.061.893.994.38
105.721.85.445.795.64.52
114.414.876.65.913.086.9
124.233.344.655.924.425.08
135.876.686.424.311.916.99
144.636.513.734.296.225.29
155.352.282.745.624.066.16
163.534.412.496.615.524.26
173.682.854.886.115.511.21
183.992.814.63.482.591.62
192.436.663.033.633.421.6
203.646.96.915.216.623.08
215.512.095.94.632.555.2
225.083.014.385.492.243
236.932.974.55.812.625.43
244.512.64.064.025.641.61
251.066.15.466.774.485.03
261.686.536.911.34.312.33
272.244.633.35.315.334.12
286.645.493.274.451.384.76
294.693.762.653.044.786.64
304.745.744.042.481.891.54
311.014.163.585.632.614.81
323.962.144.065.012.563.86
333.415.063.462.171.443.99
346.993.593.974.234.793.47
355.045.491.71.44.241.59
362.822.186.462.761.873.2
Data
Cells with Data Validation
CellAllowCriteria
J3,J6List=$B$1:$G$1



Thank you,
 

Excel Facts

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.
I don't see any countries in your example, so I've assumed column A.

Sample Data.xlsm
ABCDEFGHIJKL
1CountryABCDEF
2A1.254.651.733.6846.47
3B4.56.265.14.321.231.57First ChooseA
4C3.65.31.076.213.861.01
5D6.752.381.424.016.075.25
6E5.873.172.896.642.921.47Second ChooseC
7F5.281.641.483.873.441.73
8G4.822.732.854.474.211.3Top 10Top 5
9H6.225.181.061.893.994.38AG6.99L6.42
10I5.721.85.445.795.64.52V6.93T5.9
11J4.414.876.65.913.086.9D6.75I5.44
12K4.233.344.655.924.425.08AA6.64V4.5
13L5.876.686.424.311.916.99H6.22AG3.97
14M4.636.513.734.296.225.29E5.87
15N5.352.282.745.624.066.16L5.87
16O3.534.412.496.615.524.26I5.72
17P3.682.854.886.115.511.21T5.51
18Q3.992.814.63.482.591.62N5.35
19R2.436.663.033.633.421.6
20S3.646.96.915.216.623.08
21T5.512.095.94.632.555.2
22U5.083.014.385.492.243
23V6.932.974.55.812.625.43
24W4.512.64.064.025.641.61
25X1.066.15.466.774.485.03
26Y1.686.536.911.34.312.33
27Z2.244.633.35.315.334.12
28AA6.645.493.274.451.384.76
29AB4.693.762.653.044.786.64
30AC4.745.744.042.481.891.54
31AD1.014.163.585.632.614.81
32AE3.962.144.065.012.563.86
33AF3.415.063.462.171.443.99
34AG6.993.593.974.234.793.47
35AH5.045.491.71.44.241.59
36AI2.822.186.462.761.873.2
Sheet13
Cell Formulas
RangeFormula
I9:I18I9=INDEX($A:$A,AGGREGATE(15,6,ROW($A$2:$A$36)/(INDEX($B$2:$G$36,0,MATCH($J$3,$B$1:$G$1,0))=J9),COUNTIF(J$9:J9,J9)))
J9:J18J9=AGGREGATE(14,6,INDEX($B$2:$G$36,0,MATCH($J$3,$B$1:$G$1,0)),ROWS(I$9:I9))
K9:K13K9=INDEX($A:$A,AGGREGATE(15,6,ROW($A$2:$A$36)/ISNUMBER(MATCH($A$2:$A$36,$I$9:$I$18,0))/(INDEX($B$2:$G$36,0,MATCH($J$6,$B$1:$G$1,0))=L9),COUNTIF(L$9:L9,L9)))
L9:L13L9=AGGREGATE(14,6,INDEX($B$2:$G$36,0,MATCH($J$6,$B$1:$G$1,0))/ISNUMBER(MATCH($A$2:$A$36,$I$9:$I$18,0)),ROWS(K$9:K9))
Cells with Data Validation
CellAllowCriteria
J3,J6List=$B$1:$G$1
 
Upvote 0
Thank you Jason,
But I meant something else,
Apparently I didn't explain myself correctly so I'll show a more detailed example.
I want to sort through 2 columns using functions,
When finally I will see only the 5 countries (in column A) that the first sort will be by cell J3 and the second sort will be by cell J6,

The following is a more detailed example:

חוברת2.xlsx
ABCDEFGHIJ
1StateABCDEF
2 Alabama2.671.672.331.673.672
3 Alaska23.673.6731.673.67First ChooseA
4 Arizona2.673322.332.33
5 Arkansas222.331.3333
6 California1.672.671.67333Second ChooseC
7 Colorado1.671.3333.672.332
8 Connecticut2.6721.331.3332
9 Delaware2.333.6733.672.333.67
10 Florida2.3322.67231.33
11 Georgia1.332222.333
12 Hawaii22.671.33232.33
13 Idaho33.67322.673.67
14 Illinois2.331.332.331.332.672
15 Indiana2.332.333.671.331.671.67
16 Iowa3332.333.672.67
17 Kansas331.672.331.332
18 Kentucky[E]333.672.671.331.67
19 Louisiana2.671.331.331.332.332.33
20 Maine1.6731.6731.332.33
21 Maryland1.673.672.3321.673.67
22 Massachusetts[E]3231.332.332
23 Michigan23.672.331.673.672.67
24 Minnesota1.332.672.332.673.672.33
25 Mississippi2.331.671.673.6733
26 Missouri2.331.673.6722.333.67
27 Montana21.67231.672.67
28 Nebraska2.672.672.671.3323
29 Nevada3.673.671.672.673.673
30 New Hampshire1.333.6731.671.673
31 New Jersey1.331.331.672.671.672
32 New Mexico332.331.672.331.67
33 New York1.672.332.67233.67
34 North Carolina2.33232.673.673
35 North Dakota3.671.6722.673.673.67
36 Ohio2.6732.333.671.673
Data
Cells with Data Validation
CellAllowCriteria
J3,J6List=$B$1:$G$1


This will be the result:


חוברת2.xlsx
ABCDEFG
1StateABCDEF
2 North Dakota3.671.6722.673.673.67
3 Nevada3.673.671.672.673.673
4 Kentucky[E]333.672.671.331.67
5 Idaho33.67322.673.67
6 Iowa3332.333.672.67
Data
 
Upvote 0
You will not be able to sort and filter the original table with formulas if that is what you mean, the best that you will be able to do with formulas is to reproduce the table in another part of the sheet.

Using my existing suggestion as a starting point, you could then sort the countries in K9:K13 in another column, then use the country names with vlookup to get the rest of the data from the table.

Will that do what you need?
 
Upvote 0
Would you mind to add a helper-column?
What you could do is add a column in which you muliply the results of column B (header A) by a large number, and add to that the results of column D (header C).

Assume this formula is placed in column H. Using the example you posted in reply #3 (first table), the formula would be:
H2 = ($B2*10,000)+$D2 = 26,702.33
H3 = ($B3*10,000)+$D3 = 20,003.67
H4 = ($B4*10,000)+$D4 = 26,703.00
and so on

If you create a ranking formula based on this new column, you would be able to sort the results to get the same order as in your second table (ND=1, NV=2, KY=3, ID=4, IA=5)
 
Upvote 0
You will not be able to sort and filter the original table with formulas if that is what you mean, the best that you will be able to do with formulas is to reproduce the table in another part of the sheet.

Using my existing suggestion as a starting point, you could then sort the countries in K9:K13 in another column, then use the country names with vlookup to get the rest of the data from the table.

Will that do what you need?

If I would like only sort by 2 columns (without filter), that the main sort will be by J3 ant then sort by J6 - Is it possible?
 
Upvote 0
Would you mind to add a helper-column?
What you could do is add a column in which you muliply the results of column B (header A) by a large number, and add to that the results of column D (header C).

Assume this formula is placed in column H. Using the example you posted in reply #3 (first table), the formula would be:
H2 = ($B2*10,000)+$D2 = 26,702.33
H3 = ($B3*10,000)+$D3 = 20,003.67
H4 = ($B4*10,000)+$D4 = 26,703.00
and so on

If you create a ranking formula based on this new column, you would be able to sort the results to get the same order as in your second table (ND=1, NV=2, KY=3, ID=4, IA=5)

Interesting idea,
The problem is that the columns chaging according to the data validation...
 
Upvote 0
You need helpers of some kind, it will be impossible without. Here's what I had in mind, is it something that you can use?

The section with the yellow fill contains all of the helpers that feed the results table in I20:O25
Sample Data.xlsm
ABCDEFGHIJKLMNO
1StateABCDEF
2Alabama2.671.672.331.673.672
3Alaska23.673.6731.673.67First ChooseA
4Arizona2.673322.332.33
5Arkansas222.331.3333
6California1.672.671.67333Second ChooseC
7Colorado1.671.3333.672.332
8Connecticut2.6721.331.3332Top 101st2ndrank
9Delaware2.333.6733.672.333.67Nevada3.671.672
10Florida2.3322.67231.33North Dakota3.6721
11Georgia1.332222.333Idaho334
12Hawaii22.671.33232.33Iowa335
13Idaho33.67322.673.67Kansas31.678
14Illinois2.331.332.331.332.672Kentucky[E]33.673
15Indiana2.332.333.671.331.671.67Massachusetts[E]336
16Iowa3332.333.672.67New Mexico32.337
17Kansas331.672.331.332    
18Kentucky[E]333.672.671.331.67    
19Louisiana2.671.331.331.332.332.33
20Maine1.6731.6731.332.33StateABCDEF
21Maryland1.673.672.3321.673.67North Dakota3.671.6722.673.673.67
22Massachusetts[E]3231.332.332Nevada3.673.671.672.673.673
23Michigan23.672.331.673.672.67Kentucky[E]333.672.671.331.67
24Minnesota1.332.672.332.673.672.33Idaho33.67322.673.67
25Mississippi2.331.671.673.6733Iowa3332.333.672.67
26Missouri2.331.673.6722.333.67
27Montana21.67231.672.67
28Nebraska2.672.672.671.3323
29Nevada3.673.671.672.673.673
30New Hampshire1.333.6731.671.673
31New Jersey1.331.331.672.671.672
32New Mexico332.331.672.331.67
33New York1.672.332.67233.67
34North Carolina2.33232.673.673
35North Dakota3.671.6722.673.673.67
36Ohio2.6732.333.671.673
Sheet13
Cell Formulas
RangeFormula
I9:I18I9=IF(J9="","",INDEX($A:$A,AGGREGATE(15,6,ROW($A$2:$A$36)/(INDEX($B$2:$G$36,0,MATCH($J$3,$B$1:$G$1,0))=J9),COUNTIF(J$9:J9,J9))))
J9:J18J9=IF(ROWS(J$9:J9)>COUNTIF(INDEX($B$2:$G$36,0,MATCH($J$3,$B$1:$G$1,0)),">="&LARGE(INDEX($B$2:$G$36,0,MATCH($J$3,$B$1:$G$1,0)),5)),"",AGGREGATE(14,6,INDEX($B$2:$G$36,0,MATCH($J$3,$B$1:$G$1,0)),ROWS(J$9:J9)))
K9:K18K9=IF(J9="","",INDEX($B$2:$G$36,MATCH(I9,$A$2:$A$36,0),MATCH($J$6,$B$1:$G$1,0)))
L9:L18L9=IF(K9="","",COUNTIFS($J$9:$J$18,">"&J9)+COUNTIFS($J$9:$J$18,J9,$K$9:$K$18,">"&K9)+COUNTIFS($J$9:$J9,J9,$K$9:$K9,K9))
I21:I25I21=INDEX($I$9:$I$18,MATCH(SMALL($L$9:$L$18,ROWS(I$21:I21)),$L$9:$L$18,0))
J21:O25J21=INDEX($B$2:$G$36,MATCH($I21,$A$2:$A$36,0),MATCH(J$20,$B$1:$G$1,0))
Named Ranges
NameRefers ToCells
_FilterDatabase=Sheet13!$A$1:$G$36I9:I18
Cells with Conditional Formatting
CellConditionCell FormatStop If True
J21:O25Expression=J$20=$J$6textNO
J21:O25Expression=J$20=$J$3textNO
Cells with Data Validation
CellAllowCriteria
J3,J6List=$B$1:$G$1
 
Upvote 0
Interesting idea,
The problem is that the columns chaging according to the data validation...
You could use this formula instead of the one I mentioned earlier.
But it will only work for the columns with numerical values. Not for column A (header State).

=INDEX($A2:$G2,1,MATCH($J$3,$A$1:$G$1,0))*10000+INDEX($A2:$G2,1,MATCH($J$6,$A$1:$G$1,0))
 
Upvote 0
Actually, let me update the formula just a bit more, so it will also work in case both selected columns have same data:

=INDEX($C2:$I2;1;MATCH($L$3;$C$1:$I$1;0))*10000+INDEX($C2:$I2;1;MATCH($L$6;$C$1:$I$1;0))+((100-ROW())/1000000000)
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,178
Members
453,021
Latest member
Justyna P

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