Baseball Series Wins, Losses, and Ties

Stephen_IV

Well-known Member
Joined
Mar 17, 2003
Messages
1,171
Office Version
  1. 365
  2. 2019
Platform
  1. Windows
I want to thank James006 for helping me with my last post. In this post I would like to calculate Wins, Losses, and Ties for a series please see below. Thanks in advance!

A series refers to two or more consecutive games played between the same two teams

Book1
ABCDEFGHIJKL
1DateOppW/LTeamWLT
24/8/2023BOSWBOS11
34/9/2023BOSWTOR31
44/10/2023BOSLBAL31
54/11/2023TORLDET2
64/12/2023TORWCLE2
74/13/2023TORLKCR1
84/14/2023TORWTEX1
94/15/2023BALLCHW11
104/16/2023BALWTBR21
114/17/2023BALLLAA1
124/19/2023DETWMIN1
134/20/2023DETWCHC1
144/21/2023DETLHOU1
154/22/2023CLEWOAK1
164/23/2023CLEWPIT1
174/24/2023CLEW
184/26/2023BALW
194/27/2023BALW
204/28/2023BALW
214/29/2023KCRW
224/30/2023KCRW
235/1/2023KCRW
245/2/2023TORW
255/3/2023TORW
265/4/2023TORL
275/8/2023TEXW
285/8/2023TEXL
295/9/2023TEXW
305/10/2023TORW
315/11/2023TORW
325/12/2023CHWW
335/13/2023CHWW
345/14/2023CHWL
355/15/2023CHWW
365/16/2023BALW
375/17/2023BALW
385/18/2023BALW
395/19/2023BALL
405/21/2023CHWW
415/22/2023CHWL
425/22/2023CHWL
435/23/2023BALL
445/24/2023BALW
455/25/2023BALW
465/26/2023TBRW
475/27/2023TBRW
485/28/2023TBRL
495/29/2023TBRL
505/31/2023LAAW
516/2/2023LAAW
526/2/2023LAAW
536/3/2023DETW
546/4/2023DETW
556/5/2023DETW
566/7/2023MINW
576/8/2023MINL
586/9/2023MINW
596/10/2023CHCW
606/11/2023CHCW
616/12/2023CHCW
626/14/2023TBRW
636/15/2023TBRW
646/16/2023TBRW
656/17/2023TORW
666/18/2023TORW
676/19/2023TORL
686/20/2023TBRW
696/21/2023TBRL
706/22/2023TBRW
716/23/2023HOUW
726/24/2023HOUL
736/25/2023HOUL
746/26/2023HOUW
756/27/2023OAKW
766/28/2023OAKW
776/29/2023OAKW
786/30/2023HOUL
797/2/2023CLEW
807/2/2023CLEW
817/3/2023CLEL
827/5/2023PITL
837/6/2023PITW
847/7/2023BOSW
857/8/2023BOSW
867/9/2023BOSL
877/10/2023BOSL
Sheet1
Cell Formulas
RangeFormula
H2:H16H2=UNIQUE(B2:B87)
Dynamic array formulas.
 

Excel Facts

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).
Is data in the second table (to the right) the actual counts of W, L, T? If not maybe provide real results so we know what to see if a solution works.

I am trying to understand the objective.

Scenarios

1. There are two BOSs in a row and both are wins (W W). Does that count as one or two wins in the table?

2. There are three BOSs in a row and each is a win (W W W). Does that count as one or three wins in the table?

3. There are three BOSs in a row and wind/losses are W L W. Does that count as none, one or two?
 
Upvote 0
This should help.
Book1
ABCD
1DateOppW/L
24/8/2023BOSWW
34/9/2023BOSW
44/10/2023BOSL
54/11/2023TORLT
64/12/2023TORW
74/13/2023TORL
84/14/2023TORW
94/15/2023BALLL
104/16/2023BALW
114/17/2023BALL
124/19/2023DETWW
134/20/2023DETW
144/21/2023DETL
154/22/2023CLEWW
164/23/2023CLEW
174/24/2023CLEW
184/26/2023BALWW
194/27/2023BALW
204/28/2023BALW
214/29/2023KCRWW
224/30/2023KCRW
235/1/2023KCRW
245/2/2023TORWW
255/3/2023TORW
265/4/2023TORL
275/8/2023TEXWW
285/8/2023TEXL
295/9/2023TEXW
305/10/2023TORWW
315/11/2023TORW
325/12/2023CHWWW
335/13/2023CHWW
345/14/2023CHWL
355/15/2023CHWW
365/16/2023BALWW
375/17/2023BALW
385/18/2023BALW
395/19/2023BALL
405/21/2023CHWWL
415/22/2023CHWL
425/22/2023CHWL
435/23/2023BALLW
445/24/2023BALW
455/25/2023BALW
465/26/2023TBRWT
475/27/2023TBRW
485/28/2023TBRL
495/29/2023TBRL
505/31/2023LAAWW
516/2/2023LAAW
526/2/2023LAAW
536/3/2023DETWW
546/4/2023DETW
556/5/2023DETW
566/7/2023MINWW
576/8/2023MINL
586/9/2023MINW
596/10/2023CHCWW
606/11/2023CHCW
616/12/2023CHCW
626/14/2023TBRWW
636/15/2023TBRW
646/16/2023TBRW
656/17/2023TORWW
666/18/2023TORW
676/19/2023TORL
686/20/2023TBRWW
696/21/2023TBRL
706/22/2023TBRW
716/23/2023HOUWT
726/24/2023HOUL
736/25/2023HOUL
746/26/2023HOUW
756/27/2023OAKWW
766/28/2023OAKW
776/29/2023OAKW
786/30/2023HOUL
797/2/2023CLEWW
807/2/2023CLEW
817/3/2023CLEL
827/5/2023PITLT
837/6/2023PITW
847/7/2023BOSWT
857/8/2023BOSW
867/9/2023BOSL
877/10/2023BOSL
Sheet1
 
Upvote 0
As far as I can tell the attached workbook does what you want. Note that it is macro enabled as I found it necessary to use a "user defined function" (UDF) to do what you want.

The workbook is HERE.

Here is the function. Often other listers improve my code, sometimes a lot.

VBA Code:
Function GetCount(psTeam As String, prAnchorCellTeamsGames As Range, psWLT As String) As Long

'   This is the "header" cell for the column containg teams for each game.
'   As of 4/16/23 this is cell B1.
    Dim rAnchorCellTeamsGames As Range
    
'   Range containg team names in the games data.
    Dim rRangeTeams As Range
    
'   Used for looping
    Dim rCell As Range
    
'   Count of consecutive games found (i.e., for a series)
    Dim iConsecutivesFound As Long
    
'   For a given series these two variables contain a count of wins and losses.
    Dim iWinsInASeries As Long
    Dim iLossesInASeries As Long

'   For all series (for the specified team) these three variables contain
'   a count of wins, losses and ties.
    Dim iWinsAllSeries As Long
    Dim iLossesAllSeries As Long
    Dim iTiesAllSeries As Long
    
'   Number of games in the games data to process.
    Dim iGameRows As Long
    
'   The current team in the games data being processed.
    Dim sTeamCurrent As String
    
'   The next team in the games data to be processed.
    Dim sTeamNext As String
    
    sTeamNext = ""
    
    sTeamCurrent = ""
    
    iWinsInASeries = 0
    
    iLossesInASeries = 0
    
    iWinsAllSeries = 0
    
    iLossesAllSeries = 0
    
    iTiesAllSeries = 0
    
'   Count rows containg teams in the games data.
    iGameRows = prAnchorCellTeamsGames.Offset(100000).End(xlUp).Row

'   Set range of cells containing teams in the games data.
    Set rRangeTeams = prAnchorCellTeamsGames.Offset(1).Resize(iGameRows - 1)

'   Process all cells in the Teams cells range.
    For Each rCell In rRangeTeams
    
        sTeamCurrent = rCell.Value
    
        sTeamNext = rCell.Offset(1).Value
    
'       Look for cells containing consecutive games with the same team -- a series.
        If sTeamCurrent = psTeam _
         Then
            iConsecutivesFound = iConsecutivesFound + 1
        Else
            
            iConsecutivesFound = 0
            iWinsInASeries = 0
            iLossesInASeries = 0
        
        End If
        
'       If consecutive cells include the same team -- a series -- then
'       increment iWinsInASeries or iLossesInASeries.
        If iConsecutivesFound <> 0 _
         Then
            
            If rCell.Offset(0, 1).Value = "W" _
             Then
                iWinsInASeries = iWinsInASeries + 1
            Else
                iLossesInASeries = iLossesInASeries + 1
            End If

        End If

'       If we have encountered the end of a series then consecutive games found > 0
'       And the next team to process is not the same as the current team.
        If iConsecutivesFound <> 0 And sTeamNext <> sTeamCurrent _
         Then
            If iWinsInASeries = iLossesInASeries _
             Then
                iTiesAllSeries = iTiesAllSeries + 1
            
            ElseIf iWinsInASeries > iLossesInASeries _
             Then
                iWinsAllSeries = iWinsAllSeries + 1
            Else
                iLossesAllSeries = iLossesAllSeries + 1
            End If
            
        End If

    Next rCell
    
'   Return the "type" of value specified by parameter psWLT:
'   1. WINS All Series, or 2. LOSSES All Series, or 3. TIES All Series
    
    If psWLT = "W" _
     Then
        GetCount = iWinsAllSeries
    ElseIf psWLT = "L" _
     Then
        GetCount = iLossesAllSeries
    Else
        GetCount = iTiesAllSeries
    End If

End Function
 
Upvote 0
OaklandJim that does the job! I appreciate it. Thanks for spending your time on this post. I greatly appreciate your help!
 
Upvote 0
A comment in the code is incorrect.

This line of code
VBA Code:
'       If we have encountered the end of a series then consecutive games found > 0

Should be this
VBA Code:
'       If we have encountered the end of a series then consecutive games found <> 0
 
Upvote 0
I know that you have a VBA solution but I have been working on a Dynamic Array for this:
VBA Code:
=VSTACK({"Home","W","L","T"},LET(ra,B2:B87,rb,C2:C87,a,TEXTSPLIT(TEXTBEFORE(UNIQUE(ra&"|"&LET(b,ra,SCAN(0,SEQUENCE(ROWS(b)),LAMBDA(s,c,IF(c=1,1,IF(INDEX(b,c-1)<>INDEX(b,c),s+1,s)))))),"|"),"-","|"),
u,UNIQUE(TEXTSPLIT(TEXTBEFORE(UNIQUE(ra&"|"&LET(b,B2:B87,SCAN(0,SEQUENCE(ROWS(b)),LAMBDA(s,c,IF(c=1,1,IF(INDEX(b,c-1)<>INDEX(b,c),s+1,s)))))),"|"),"-","|")),
h,LET(u,SCAN(0,SEQUENCE(ROWS(ra)),LAMBDA(s,c,IF(c=1,1,IF(INDEX(ra,c-1)<>INDEX(ra,c),s+1,s)))),v,UNIQUE(ra&"|"&LET(b,ra,SCAN(0,SEQUENCE(ROWS(b)),LAMBDA(s,c,IF(c=1,1,IF(INDEX(b,c-1)<>INDEX(b,c),s+1,s)))))),s,BYROW(v,LAMBDA(x,SUMPRODUCT(--(ra&"|"&u=x)*(rb="W")/SUMPRODUCT(--(ra&"|"&u=x)*(rb<>""))))),IF(s>0.5,"W",IF(s<0.5,"L","T"))),
m,MAP(u,LAMBDA(x,SUM(IF(ISERROR(FILTER(a,(x=a)*(h="W"))),0,1)))),
n,MAP(u,LAMBDA(x,SUM(IF(ISERROR(FILTER(a,(x=a)*(h="L"))),0,1)))),
o,MAP(u,LAMBDA(x,SUM(IF(ISERROR(FILTER(a,(x=a)*(h="T"))),0,1)))),
HSTACK(u,m,n,o)))
 
Upvote 0
Thank you so much. I appreciate all of the help and guidance. Did not know that was even possible. I greatly appreciate it.
 
Upvote 0

Forum statistics

Threads
1,215,583
Messages
6,125,665
Members
449,247
Latest member
wingedshoes

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