=LARGE(B$2:B$11,D2)
=INDEX(A$2:A$11,MATCH(F2,B$2:B$11,0))
let
Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Sales", Int64.Type}}),
#"Sorted Rows" = Table.Sort(#"Changed Type",{{"Sales", Order.Descending}}),
#"Added Index" = Table.AddIndexColumn(#"Sorted Rows", "Index", 1, 1, Int64.Type),
#"Filtered Rows" = Table.SelectRows(#"Added Index", each [Index] <= 5),
#"Removed Columns" = Table.RemoveColumns(#"Filtered Rows",{"Index"})
in
#"Removed Columns"
Not just hairy - it wouldn't work.Note that think could get a little hairy if the Sales values are not unique,
25 01 23.xlsm | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|
A | B | C | D | E | F | G | H | |||
1 | Region | Sales | Region | Sales | Region | Sales | ||||
2 | A | 230 | D | 987 | D | 987 | ||||
3 | B | 456 | E | 888 | E | 888 | ||||
4 | C | 770 | F | 888 | F | 888 | ||||
5 | D | 987 | C | 770 | C | 770 | ||||
6 | E | 888 | B | 456 | B | 456 | ||||
7 | F | 888 | H | 456 | ||||||
8 | G | 234 | J | 456 | ||||||
9 | H | 456 | ||||||||
10 | I | 347 | ||||||||
11 | J | 456 | ||||||||
Top 5 |
Cell Formulas | ||
---|---|---|
Range | Formula | |
D2:D11 | D2 | =IF(E2="","",INDEX(A:A,AGGREGATE(15,6,ROW(A$2:A$11)/(B$2:B$11=E2),COUNTIF(E$2:E2,E2)))) |
E2:E11 | E2 | =IF(LARGE(B$2:B$11,ROWS(E$2:E2))<LARGE(B$2:B$11,5),"",LARGE(B$2:B$11,ROWS(E$2:E2))) |
G2:G6 | G2 | =INDEX(A:A,AGGREGATE(15,6,ROW(A$2:A$11)/(B$2:B$11=E2),COUNTIF(E$2:E2,E2))) |
H2:H6 | H2 | =LARGE(B$2:B$11,ROWS(H$2:H2)) |
=VSTACK({"Rank","Region","Sales"},HSTACK(SEQUENCE(5,1,1,1),TAKE(SORTBY(A2:B11,B2:B11,-1),5,2)))
=LET(filteredtable,FILTER(A2:B11,B2:B11>INDEX(SORT(UNIQUE(B2:B11),,-1),5,1)),sorted,SORTBY(filteredtable,CHOOSECOLS(filteredtable,2),-1),hstacked,HSTACK(SEQUENCE(COUNT(sorted),1,1),sorted),VSTACK({"Rank","Region","Sales"},hstacked))
=LET(filteredtable,FILTER(A2:B11,B2:B11>INDEX(SORT(UNIQUE(B2:B11),,-1),5,1)),sorted,SORTBY(filteredtable,CHOOSECOLS(filteredtable,2),-1),ranks,BYROW(sorted,LAMBDA(row,MATCH(INDEX(row,1,2),SORT(UNIQUE(B2:B11),,-1),0))),VSTACK({"Rank","Region","Sales"},HSTACK(ranks,sorted)))
Rank | Region | Sales |
1 | D | 987 |
2 | E | 888 |
3 | F | 888 |
4 | C | 770 |
5 | B | 456 |
987 |
888 |
770 |
456 |
230 |