How to tally tennis court pairings?

JenniferMurphy

Well-known Member
Joined
Jul 23, 2011
Messages
2,691
Office Version
  1. 365
Platform
  1. Windows
Once a month, each member of our tennis group submits the days that they are available to play doubles. The person in charge of court scheduling then assigns the available players to a court. We have been doing this for years. The scheduler tries to mix up the players so that we each one gets a chance to play with as many dfferent players as possible.

I thought it might be interesting to tally the number of times each player has been paired with each other player. With N players, there would be N * (N-1) / 2 2-player pairings. We have about 20 players. That would be 19 pairings.

Here is some sample data with just 6 players (= 15 pairings). There are 3 tables. TblPlayers is a list of the players. TblCourts is a list of the court assignments. TblTallies is a list of the pairings with tallies for each. The first 2 tables are the input data. TblTallies is the one that needs to be generated. I don't see any way to do that in Excel, so my plan is to write a macro. I would appreciate any suggestions.

Tennis Pairings.xlsx
BCDEFG
3TblPlayersTblCourtsTblTallies
4NameCourt AssignmentPairingTally
5DebbieJill Nancy Debbie EmilyEmily Linda0
6EmilySusan Jill Debbie LindaEmily Jill1
7JillNancy Jill Debbie LindaLinda Susan1
8LindaNancy Susan Emily DebbieEmily Susan1
9NancyDebbie Nancy Susan JillLinda Nancy1
10Susan5Debbie Emily2
116Debbie Linda2
12Emily Nancy2
13Jill Linda2
14Jill Susan2
15Nancy Susan2
16Debbie Susan3
17Jill Nancy3
18Debbie Jill4
19Debbie Nancy4
201530
Sheet1
Cell Formulas
RangeFormula
D10D10=SUBTOTAL(103,[Court Assignment])
B11B11=SUBTOTAL(103,[Name])
F20F20=SUBTOTAL(103,[Pairing])
G20G20=SUBTOTAL(109,[Tally])


I added the table names aboe each table because xl2bb does not report table names.
 

Excel Facts

Format cells as date
Select range and press Ctrl+Shift+3 to format cells as date. (Shift 3 is the # sign which sort of looks like a small calendar).
How about
Excel Formula:
=COUNTIFS($D$5:$D$9,"*"&TEXTBEFORE(F5," ")&"*",$D$5:$D$9,"*"&TEXTAFTER(F5," ")&"*")
 
Upvote 0
How about
Excel Formula:
=COUNTIFS($D$5:$D$9,"*"&TEXTBEFORE(F5," ")&"*",$D$5:$D$9,"*"&TEXTAFTER(F5," ")&"*")
Wow!!! That seems to work. Very nice. I modified your code to use table notation. My manual tallies are Tally1, yours are Tally2.

Tennis Pairings.xlsx
BCDEFGH
3TblPlayersTblCourtsTblTallies
4NameCourt AssignmentPairingTally1Tally2
5DebbieJill Nancy Debbie EmilyEmily Linda00
6EmilySusan Jill Debbie LindaEmily Jill11
7JillNancy Jill Debbie LindaLinda Susan11
8LindaNancy Susan Emily DebbieEmily Susan11
9NancyDebbie Nancy Susan JillLinda Nancy11
10Susan5Debbie Emily22
116Debbie Linda22
12Emily Nancy22
13Jill Linda22
14Jill Susan22
15Nancy Susan22
16Debbie Susan33
17Jill Nancy33
18Debbie Jill44
19Debbie Nancy44
20153030
Sheet1
Cell Formulas
RangeFormula
D10D10=SUBTOTAL(103,[Court Assignment])
B11B11=SUBTOTAL(103,[Name])
H5:H19H5=COUNTIFS(TblCourts[Court Assignment],"*"&TEXTBEFORE([@Pairing]," ")&"*",TblCourts[Court Assignment],"*"&TEXTAFTER([@Pairing]," ")&"*")
F20F20=SUBTOTAL(103,[Pairing])
G20G20=SUBTOTAL(109,[Tally1])
H20H20=SUBTOTAL(109,[Tally2])


And it continues to work if I add more Court Assignments.

Tennis Pairings.xlsx
BCDEFG
3TblPlayersTblCourtsTblTallies
4NameCourt AssignmentPairingTally2
5DebbieJill Nancy Debbie EmilyEmily Linda1
6EmilySusan Jill Debbie LindaLinda Nancy1
7JillNancy Jill Debbie LindaEmily Jill2
8LindaNancy Susan Emily DebbieLinda Susan2
9NancyDebbie Nancy Susan JillJill Linda2
10SusanDebbie Susan Emily LindaEmily Susan3
116Emily Nancy Susan JillDebbie Emily3
127Debbie Linda3
13Emily Nancy3
14Jill Susan3
15Nancy Susan3
16Debbie Susan4
17Jill Nancy4
18Debbie Jill4
19Debbie Nancy4
201542
Sheet1
Cell Formulas
RangeFormula
B11B11=SUBTOTAL(103,[Name])
D12D12=SUBTOTAL(103,[Court Assignment])
G5:G19G5=COUNTIFS(TblCourts[Court Assignment],"*"&TEXTBEFORE([@Pairing]," ")&"*",TblCourts[Court Assignment],"*"&TEXTAFTER([@Pairing]," ")&"*")
F20F20=SUBTOTAL(103,[Pairing])
G20G20=SUBTOTAL(109,[Tally2])


The problem arises if I add any new players. Here I added Wendy to TblPlayers and a new row to TblCourts with Wendy playing. Then I have to manually add N-1 rows to TblTallies.

Tennis Pairings.xlsx
BCDEFG
3TblPlayersTblCourtsTblTallies
4NameCourt AssignmentPairingTally2
5DebbieJill Nancy Debbie EmilyEmily Wendy0
6EmilySusan Jill Debbie LindaJill Wendy0
7JillNancy Jill Debbie LindaSusan Wendy0
8LindaNancy Susan Emily DebbieEmily Linda1
9NancyDebbie Nancy Susan JillDebbie Wendy1
10SusanDebbie Susan Emily LindaLinda Wendy1
11WendyEmily Nancy Susan JillNancy Wendy1
127Debbie Wendy Linda NancyLinda Nancy2
138Emily Jill2
14Linda Susan2
15Jill Linda2
16Emily Susan3
17Debbie Emily3
18Emily Nancy3
19Jill Susan3
20Nancy Susan3
21Debbie Linda4
22Debbie Susan4
23Jill Nancy4
24Debbie Jill4
25Debbie Nancy5
262148
Sheet1
Cell Formulas
RangeFormula
B12B12=SUBTOTAL(103,[Name])
D13D13=SUBTOTAL(103,[Court Assignment])
G5:G25G5=COUNTIFS(TblCourts[Court Assignment],"*"&TEXTBEFORE([@Pairing]," ")&"*",TblCourts[Court Assignment],"*"&TEXTAFTER([@Pairing]," ")&"*")
F26F26=SUBTOTAL(103,[Pairing])
G26G26=SUBTOTAL(109,[Tally2])


Your solution is very cool, but with 20 players and new ones added from time to time, manually adding rows to TblTallies wuold be tedious and error prone. I am looking for a solution that generates the entire TblTallies table from scratch based on the contents of TblPlayers & TblCourts.

I also want to add another table that shows who was available to play each day and use that to calculate the percentage of the days that each player was selected when they were available.

I think I will need a macro for all that. Do you agree?
 
Upvote 0
auto populate the whole result table:

VBA Code:
=LET(s,DROP(REDUCE(0,B5:B9,LAMBDA(x,y,VSTACK(x,DROP(IFNA(HSTACK(y,y:B10),y),1)))),1),VSTACK({"Player1","Player2","Tally"},HSTACK(s,BYROW(s,LAMBDA(x,SUM(N(BYROW(FIND(x,D5:D9),LAMBDA(y,COUNT(y)=2)))))))))
1701827593446.png
 
Upvote 0
auto populate the whole result table:

VBA Code:
=LET(s,DROP(REDUCE(0,B5:B9,LAMBDA(x,y,VSTACK(x,DROP(IFNA(HSTACK(y,y:B10),y),1)))),1),VSTACK({"Player1","Player2","Tally"},HSTACK(s,BYROW(s,LAMBDA(x,SUM(N(BYROW(FIND(x,D5:D9),LAMBDA(y,COUNT(y)=2)))))))))

Impressive, very impressive. I am afraid you guys are just a few levels over my head. It is amazing to see what Excel is capable of if you know what you are doing. Amazing.

Thanks
 
Upvote 0
B5:B9=drop the last row of TblPlayers range
B10=the last cell in Tblayers range

If you add rows, change the references accordingly.
 
Upvote 0
make it shorter:
VBA Code:
=REDUCE({"Player1","Player2","Tally"},B5:B9,LAMBDA(x,y,VSTACK(x,DROP(REDUCE(0,y:B10,LAMBDA(m,n,VSTACK(m,HSTACK(y,n,COUNT(FIND(y,D5:D9)*FIND(n,D5:D9)))))),2))))

1701829219962.png
 
Upvote 0
Impressive, very impressive. I am afraid you guys are just a few levels over my head. It is amazing to see what Excel is capable of if you know what you are doing. Amazing.

Thanks
thanks for the feedback and enjoy the day :biggrin:
 
Upvote 0
I can't edit my post #7, so post here the final formula:
VBA Code:
=REDUCE({"Player1","Player2","Tally"},B5:B9,LAMBDA(x,y,VSTACK(x,DROP(REDUCE(,y:B10,LAMBDA(m,n,VSTACK(m,HSTACK(y,n,COUNT(FIND(y,D5:D9)*FIND(n,D5:D9)))))),1))))
 
Upvote 0
I can't edit my post #7, so post here the final formula:
VBA Code:
=REDUCE({"Player1","Player2","Tally"},B5:B9,LAMBDA(x,y,VSTACK(x,DROP(REDUCE(,y:B10,LAMBDA(m,n,VSTACK(m,HSTACK(y,n,COUNT(FIND(y,D5:D9)*FIND(n,D5:D9)))))),1))))
I am totally blown away by the creative and mind-boggling (at least for me) solutions to my question. If I ever get my head around several of these new functions, I will have learned a lot. Thank you.

However, I feel a little guilty because I fear I may have been a little misleading or at least unclear about my objective. Generating the tallies is just part of the objective. I then want to calculate the percentages of the pair-wise tallies and the total tallies as compared their availability.

Also, I am more than a little wary of complicated expressions in cells -- especially if it has to be replicated on multiple cells. I am typo-prone and a little dyslexic, so I tend to get even simple expressions wrong. Expressions like the one above scare the *%$# out of me. 😯

Here's an example of what the final product might look like. Bear in mind that this is with only 7 players and for just 8 dates. We have around 20 that play regularly and a few others that play occasionally. If 8 or more are available on a given date, I will assign two courts. If 12 or more are available, I will assign 3 courts. And I think I will want to be able to generate tallies for the last 6 months, the last 12 months, and so on.

So the tables will be much larger and somewhat dynamic. I used your expression for the pairing tally. I am sure your expression could be tweaked to generate the player tally and both availability counts, too, but I am almost certain to resort to a macro, with which I am more comfortable, so I did them by hand.

Tennis Pairings.xlsx
CDEFGHIJKLMNO
3TblPlayers2TblCourts2TblTallies2
4NameTallyAvail%DateAvailableCourt1PairingTallyAvail%
5Debbie7888%11/07/23Jill Nancy Debbie EmilyJill Nancy Debbie EmilyDebbie Emily3560%
6Emily4580%11/09/23Susan Jill Debbie Linda NancySusan Jill Debbie LindaDebbie Jill4580%
7Jill55100%11/14/23Nancy Jill Debbie Linda Emily SusanNancy Jill Debbie LindaDebbie Linda4667%
8Linda4667%11/16/23Nancy Susan Emily Debbie LindaNancy Susan Emily DebbieDebbie Nancy5771%
9Nancy6786%11/21/23Debbie Nancy Susan JillDebbie Nancy Susan JillDebbie Susan4757%
10Susan5771%11/23/23Debbie Susan Emily LindaDebbie Susan Emily LindaDebbie Wendy11100%
11Wendy11100%11/28/23Emily Nancy Susan Jill Debbie LindaEmily Nancy Susan JillEmily Jill2367%
127323911/30/23Debbie Wendy Linda Nancy SusanDebbie Wendy Linda NancyEmily Linda1250%
138Emily Nancy3475%
14Emily Susan3475%
15Emily Wendy000%
16Jill Linda2367%
17Jill Nancy4580%
18Jill Susan3475%
19Jill Wendy000%
20Linda Nancy2540%
21Linda Susan2633%
22Linda Wendy11100%
23Nancy Susan3650%
24Nancy Wendy11100%
25Susan Wendy010%
26214876
Sheet2
Cell Formulas
RangeFormula
F5:F11,O5:O25F5=IF([@Avail]=0,0,[@Tally]/[@Avail])
C12C12=SUBTOTAL(103,[Name])
D12,M26D12=SUBTOTAL(109,[Tally])
E12,N26E12=SUBTOTAL(109,[Avail])
J13J13=SUBTOTAL(103,[Court1])
M5:M25M5=COUNTIFS(TblCourts2[Court1],"*"&TEXTBEFORE([@Pairing]," ")&"*",TblCourts2[Court1],"*"&TEXTAFTER([@Pairing]," ")&"*")
L26L26=SUBTOTAL(103,[Pairing])


I hope that is a little clearer.
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

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