Forum Discussion
Sort function with countif?
Is it possible to sort 2 columns based on the second when the second is using counif? I am tracking wins in a round robin badminton tournament and use countif to look for winner's names in a different column. I would like for the count to automatically sort when the winner column is updated.
/
12 Replies
- DerrellSCCopper Contributor
Here is one of my Round Robin tournaments. As I update the winners in the column, it does count, but can it automatically sort the column without creating and additional "ranking" column?
- Patrick2788Silver Contributor
Perhaps this one:
=LET(uWinner,UNIQUE(TOCOL(winner,1)),k,ROWS(uWinner),stack,HSTACK(uWinner,COUNTIF(winner,uWinner)),HSTACK(SEQUENCE(k),SORT(stack,2,-1)))
- DerrellSCCopper Contributor
Patrick2788 Thank you, but I don't want to add another set of data.
- bosinanderIron Contributor
Hi DerrellSC. Just like SnowMan55 showed, the SORT function in Excel 365 can sort on column number two. And that is basically the answer to the core question.
Creating entries for all the round-robin games is a lot more complicated - see https://nrich.maths.org/1443 - but nowadays quite possible to do without macros.
Teams/Players in column B are automatically set up in Round Robin games assuming there are enough courts for all games taking place at the same time.
Adding teams in column B will automatically count new numbers in column A.
Column L holds a randomizer for who wins and should be cleared in cell L4, if used for real.
If the number of teams are odd, one will have to pause.
The 'payamas table' in a3:c10 is named Participants.
The formula used to rank them is in cell O4;
=SORT(Participants,2,-1)
There are also some hidden helper calculations prepared for up to 32 teams.
If more teams are needed, copy cell bo4 rightwards.
There are more hidden columns to do this and there are other ways to display the result etc.
So, it's a starting point that may be be helpful.
- SnowMan55Bronze Contributor
<< Is it possible to sort 2 columns based on the second when the second is using counif? >>
Yes, your second-column formula probably allows that. You can (save your workbook and then) manually try that out.
<< I would like for the count to automatically sort when the winner column is updated. >>
Well, apparently you mean for both the players' names and counts to automatically sort. The answer here is also yes, e.g., by using a "separate copy" of the data:
and a formula (in A13 in this example) that uses the SORT function:
=SORT(A3:B8,2,-1,FALSE)
(You do not have to put the Rankings data in the same columns as the Roster data; I just did that because it fits nicely.)
I have attached my workbook with that sample data (intentionally not creating entries for all the round-robin games). Note what happens when you enter a winner for game 9.
- DerrellSCCopper ContributorThank you. I was hoping to be able to do it without a having another column of data.