Return the tied values

pchatziko

New Member
Joined
Apr 30, 2021
Messages
16
Office Version
  1. 365
Platform
  1. Windows
I have some elements that i am trying to rank by a quantity then sorting them but they can be ties. I want to return an array giving me all the tied elements. The elements list will always be 4. I'm showing you some examples and the expected returns in the following minisheet. Thanks in advance

nfl (1).xlsm
FGHIJK
1elementsquantityrank quantitysortSortby quantityExpected return
2A311AA
3B311BB
4D143C
5C234D
6
7elementsquantityrank quantitysortSortby quantityExpected return
8A311AA
9B311BB
10D311DD
11C233C
12
13
14elementsquantityrank quantitysortSortby quantityExpected return
15A231BB
16B311DD
17D313AA
18C233CC
19
20elementsquantityrank quantitysortSortby quantityExpected return
21A231BA
22B313AD
23D233DC
24C233C
25
Sheet3
Cell Formulas
RangeFormula
I2:I5,I21:I24,I15:I18,I8:I11I2=SORT(H2:H5)
J2:J5,J21:J24,J15:J18,J8:J11J2=SORTBY(F2:F5,H2:H5)
H2:H5,H21:H24,H15:H18,H8:H11H2=RANK(G2,$G$2:$G$5)
Dynamic array formulas.
 

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.
Here is one idea:
MrExcel_20220505B.xlsx
FGHIJK
1elementsquantityrank quantitysortSortby quantityExpected return
2A311AA
3B311BB
4D143C
5C234D
6
7elementsquantityrank quantitysortSortby quantityExpected return
8A311AA
9B311BB
10D311DD
11C244C
12
13elementsquantityrank quantitysortSortby quantityExpected return
14A231BB
15B311DD
16D313AA
17C233CC
18
19elementsquantityrank quantitysortSortby quantityExpected return
20A221BA
21B312AD
22D222DC
23C222C
Sheet4
Cell Formulas
RangeFormula
I2:I5,I20:I23,I14:I17,I8:I11I2=SORT(H2:H5)
J2:J5,J20:J23,J14:J17,J8:J11J2=SORTBY(F2:F5,H2:H5)
K2:K3,K20:K22,K14:K17,K8:K10K2=INDEX(SORT(FILTER(F2:H5,COUNTIF(H2:H5,H2:H5)>1),3),,1)
H2:H5H2=RANK(G2,G$2:G$5)
H8:H11H8=RANK(G8,G$8:G$11)
H14:H17H14=RANK(G14,$G$14:$G$17)
H20:H23H20=RANK(G20,$G$20:$G$23)
Dynamic array formulas.
 
Upvote 0
It works some times some others not and i suspect it has to be because my elements array is not static but continuously changing therefore i get a spill error range unknown
 
Upvote 0
Did you change the formulas in column H? Notice the difference between your original post and mine. In your original post, each element in every group of four was being ranked against the same set of data...the first set--the $G$5 in =RANK(G2,$G$2:$G$5, which isn't correct. In my post, I adjusted those ranges to refer to the current set of four.
 
Upvote 0
No i'm afraid it wasn't the problem, i noticed if there is no tie the formula returns #Calc error so i added an iferror to get rid of it and i'm still getting "random" spill errors. The error at the #spill is unknown range which means the problem is the dynamic array i am using which has a root with rand() but watching it to work sometimes and sometimes not it sure is puzzling. Attaching the minisheet for more info.

nfl (1).xlsm
AFAGAHAIAJAKALAMANAO
2AFC SouthWinsTIESWins + TiesRankSort RankFind ties
31Indianapolis Colts5054Houston Texans1#SPILL!
42Tennessee Titans6063Jacksonville Jaguars2
53Jacksonville Jaguars9092Tennessee Titans3
64Houston Texans110111Indianapolis Colts4
7AFC West
81Kansas City Chiefs9092Los Angeles Chargers1#SPILL!
92Los Angeles Chargers100101Kansas City Chiefs2
103Denver Broncos6064Las Vegas Raiders2
114Las Vegas Raiders9092Denver Broncos4
12AFC North
131Baltimore Ravens100101Baltimore Ravens1#SPILL!
142Cleveland Browns100101Cleveland Browns1
153Pittsburgh Steelers8083Pittsburgh Steelers3
164Cincinnati Bengals6064Cincinnati Bengals4
17AFC East
181Buffalo Bills8083New York Jets1#SPILL!
192New England Patriots100102New England Patriots2
203Miami Dolphins7074Buffalo Bills3
214New York Jets110111Miami Dolphins4
22NFC South
231Tampa Bay Buccaneers7072Atlanta Falcons1New Orleans Saints
242New Orleans Saints5053Tampa Bay Buccaneers2Carolina Panthers
253Atlanta Falcons100101New Orleans Saints3
264Carolina Panthers5053Carolina Panthers3
Schedule
Cell Formulas
RangeFormula
AH23:AH26,AH18:AH21,AH13:AH16,AH8:AH11,AH3:AH6AH3=COUNTIFS($D$3:$D$274,AG3,$H$3:$H$274,"H")+COUNTIFS($B$3:$B$274,AG3,$H$3:$H$274,"A")
AI23:AI26,AI18:AI21,AI13:AI16,AI8:AI11,AI3:AI6AI3=COUNTIFS($D$3:$D$274,AG3,$H$3:$H$274,"T")+COUNTIFS($B$3:$B$274,AG3,$H$3:$H$274,"T")
AJ23:AJ26,AJ18:AJ21,AJ13:AJ16,AJ8:AJ11,AJ3:AJ6AJ3=AH3+AI3*0.5
AK3:AK6AK3=RANK(AJ3,$AJ$3:$AJ$6)
AL3:AL6,AL23:AL26,AL18:AL21,AL13:AL16,AL8:AL11AL3=SORTBY(AG3:AG6,AK3:AK6)
AM3:AM6,AM23:AM26,AM18:AM21,AM13:AM16,AM8:AM11AM3=SORT(AK3:AK6)
AO3,AO8AO3=IFERROR(INDEX(SORT(FILTER(AL3:AM6,COUNTIF(AM3:AM6,AM3:AM6)>1),2),,1),"")
AK8:AK11AK8=RANK(AJ8,$AJ$8:$AJ$11)
AK13:AK16AK13=RANK(AJ13,$AJ$13:$AJ$16)
AO13,AO23:AO24,AO18AO13=IFERROR(INDEX(SORT(FILTER(AL13:AM16,COUNTIF(AM13#,AM13#)>1),2),,1),"")
AK18:AK21AK18=RANK(AJ18,$AJ$18:$AJ$21)
AK23:AK26AK23=RANK(AJ23,$AJ$23:$AJ$26)
Dynamic array formulas.
 
Upvote 0
I think you're correct. I didn't realize the Wins and Ties values were coming from cells tied to volatile random numbers. I don't understand why this leads to the issue, as the "display only tied teams" formula (in the earlier post) works sometimes...but not all of the time. I couldn't work with the mini-sheet in your last post, as it references a lot of cells in columns B & D, which is where the volatile values are coming from. To simulate that, I added some random variation to the scores in the example here (keeping the variations small to produce a lot of tied rankings for troubleshooting). I tried more approaches than I can count in an attempt to find something that would reliably list teams with tied rankings. The only formula based approach that seemed to work reliably uses TEXTJOIN. The downside is this displays all tied teams in the same cell, separated by the delimiter of your choice (I've used a comma space here). I tried operating on the original team and rankings columns so as to reduce the extent of any FILTER/SORT spilling effects. The orange cell with TEXTJOIN works well. You'll see that it uses a SORT(FILTER(FILTER construction, and then joins the results in a TEXTJOIN function. Oddly, the same construction without the TEXTJOIN (yellow cell) does not work reliably. I also tried splitting the text in the orange cell to produce a list, but that too suffers from the #SPILL! issue. If the single cell listing is not satisfactory, I think VBA may offer a solution.
nfl2.xlsx
AJAKALAMANAOARASATAUAV
12AFC NorthWinsTIESWins + TiesRankSort RankFind ties
131Baltimore Ravens7074Cincinnati Bengals1Cleveland Browns, Pittsburgh Steelers#SPILL!
142Cleveland Browns8082Cleveland Browns2
153Pittsburgh Steelers8082Pittsburgh Steelers2
164Cincinnati Bengals9091Baltimore Ravens4
NFL
Cell Formulas
RangeFormula
AL13:AL16AL13=IF(ISNUMBER($AJ13),RANDBETWEEN(7,9),"")
AM13:AM16AM13=IF(ISNUMBER($AJ13),RANDBETWEEN(0,0),"")
AN13:AN16AN13=AL13+AM13*0.5
AO13:AO16AO13=RANK(AN13,$AN$13:$AN$16)
AR13:AS16AR13=FILTER(SORT(AK13:AO16,5),{1,0,0,0,1})
AT13AT13=LET( sties, SORT(FILTER(FILTER(AK13:AO16,COUNTIF(AO13:AO16,AO13:AO16)>1,""),{1,0,0,0,1}),2), TEXTJOIN(", ",TRUE,INDEX(sties,,1)))
AU13AU13=SORT(FILTER(FILTER(AK13:AO16,COUNTIF(AO13:AO16,AO13:AO16)>1,""),{1,0,0,0,1}),2)
Dynamic array formulas.
 
Upvote 0
Yes i don't see any other way other than vba. Thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,215,767
Messages
6,126,777
Members
449,336
Latest member
p17tootie

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