+ Reply to Thread
Results 1 to 13 of 13

formula for strength of schedule?

Hybrid View

  1. #1
    Registered User
    Join Date
    07-22-2008
    Location
    auburn
    Posts
    74

    formula for strength of schedule?

    So I'm trying to create a "strength of schedule" component for the football season. Having trouble thinking of a way to adjust it to reflect the average value of a team's opponents up until the current day's games. I've attached a small spreadsheet attempting to show what I'm trying to do... I manually filled in the values for "b" team's strength of schedule with an explanation of how I got to that number. Any ideas? Thanks!
    Attached Files Attached Files

  2. #2
    Registered User
    Join Date
    07-22-2008
    Location
    auburn
    Posts
    74

    Re: formula for strength of schedule?

    Any ideas?

  3. #3
    Forum Expert tigeravatar's Avatar
    Join Date
    03-25-2011
    Location
    Colorado, USA
    MS-Off Ver
    Excel 2003 - 2013
    Posts
    5,361

    Re: formula for strength of schedule?

    roasthawg,

    Attached is a modified version of your posted workbook.

    First, I simplified the formulas in column G and H. In cell G2 and copied over and down to H10 is this regular formula:
    =IF(COUNTIF($B$1:$C1,B2)>0,AVERAGEIF($B$1:$C1,B2,$D$1:$E1),"")

    Then I addressed your actual question. In cell J2 and copied over and down to cell K10 is this regular formula:
    =IF(COUNTIF($B$1:$C1,B2)=0,"",(SUMIF($B$1:$B1,B2,$E$1:$E1)+SUMIF($C$1:$C1,B2,$D$1:$D1))/COUNTIF($B$1:$C1,B2))

    Is that what you're looking for?
    Hope that helps,
    ~tigeravatar

    Forum Rules: How to use code tags, mark a thread solved, and keep yourself out of trouble

  4. #4
    Registered User
    Join Date
    07-22-2008
    Location
    auburn
    Posts
    74

    Re: formula for strength of schedule?

    I like the simplification of the first formula... thanks!

    As far as what I'm after however, still not there. The formula you gave
    =IF(COUNTIF($B$1:$C1,B2)=0,"",(SUMIF($B$1:$B1,B2,$E$1:$E1)+SUMIF($C$1:$C1,B2,$D$1:$D1))/COUNTIF($B$1:$C1,B2))
    looks like it's calculating the team's defense. I need the team's opponents AVERAGES as of the date of the current game.

    For example... on Jan 4 team "A" has played three games, one each against teams "B", "C", and "D". I want to know the AVERAGE of team's "B", "C", and "D" pts scored and pts against for all games up thru Jan 3. Make sense? If not, let me know. Thanks for the help!
    Last edited by Cutter; 08-22-2012 at 07:32 PM. Reason: Removed whole post quote

  5. #5
    Forum Expert tigeravatar's Avatar
    Join Date
    03-25-2011
    Location
    Colorado, USA
    MS-Off Ver
    Excel 2003 - 2013
    Posts
    5,361

    Re: formula for strength of schedule?

    roasthawg,

    The formula I provided gave correct results based on what you entered manually for team "b". When I checked it manually against team "a" it also provided correct results. I know the formula doesn't use Average() but it does use (Sumif()+Sumif())/Countif() in order to get the average. I had to go this route because of using opposite columns to calculate opponent average.

    If it is, in fact, yielding incorrect results, please show me what result is incorrect, what it should be instead, and how you arrived at that answer.

  6. #6
    Registered User
    Join Date
    07-22-2008
    Location
    auburn
    Posts
    74

    Re: formula for strength of schedule?

    Sorry, I wan't capitalizing AVERAGE as commentary on your use of sumifs instead of averageifs... only to try to clarify what I am after.

    Ok, here's an example of an incorrect result using your formula... in cell B8 we have team "C". The date of this game is Jan 3. Up until this point of the season team "C" has completed games against teams "E" and team "F". Prior to the start of Jan 3rd's games team "E" averaged 3 as evidenced in cell G9 and team "F" averaged 3.5 as evidenced in cell H10. The average of these two numbers is the result I'm after... 3.25 in this case. Hope that helps... thanks for taking time on this!
    Last edited by Cutter; 08-22-2012 at 07:33 PM. Reason: Removed whole post quote

  7. #7
    Forum Expert tigeravatar's Avatar
    Join Date
    03-25-2011
    Location
    Colorado, USA
    MS-Off Ver
    Excel 2003 - 2013
    Posts
    5,361

    Re: formula for strength of schedule?

    roasthawg,

    Ah, ok. That makes things much more complicated. In order to use only formulas, I had to use the MCONCAT function which is provided by the Morefunc add-in.

    Attached is version 2. Column M is a helper column. In cell M2 and copied down is this formula:
    =LOOKUP(2,1/($A$1:$A1<>$A2),ROW(INDIRECT("1:"&ROWS($A$1:$A1))))

    Then, in cell J2 and copied down to J10, then copied to cells K2:K10 is this array formula:
    =IF(COUNTIF($B$1:INDEX($C$1:$C1,$M2),$B2)=0,"",SUMPRODUCT(SUMIF($B$1:INDEX($C$1:$C1,$M2),INDEX(TRIM(MID(SUBSTITUTE(TRIM(MCONCAT(IF($B$1:INDEX($B$1:$B1,$M2)=B2,$C$1:INDEX($C$1:$C1,$M2),IF($C$1:INDEX($C$1:$C1,$M2)=B2,$B$1:INDEX($B$1:$B1,$M2),""))," "))," ",REPT(" ",99)),99*(ROW(INDIRECT("1:"&COUNTIF($B$1:INDEX($C$1:$C1,$M2),B2)))-1)+1,99)),),$D$1:$E1))/SUM(COUNTIF($B$1:INDEX($C$1:$C1,$M2),INDEX(TRIM(MID(SUBSTITUTE(TRIM(MCONCAT(IF($B$1:INDEX($B$1:$B1,$M2)=B2,$C$1:INDEX($C$1:$C1,$M2),IF($C$1:INDEX($C$1:$C1,$M2)=B2,$B$1:INDEX($B$1:$B1,$M2),""))," "))," ",REPT(" ",99)),99*(ROW(INDIRECT("1:"&COUNTIF($B$1:INDEX($C$1:$C1,$M2),B2)))-1)+1,99)),))))


    It is very long because it is very complex. You needed to get teams that had played against the current row's teams prior to the current row's date, and then average all of their scores together. This formula does that and is the only way I can think of to do so without resorting to VBA (a UDF or macro). It does however provide the correct results for team "b" and the corect results for team "c" and does so using the logic described in your most recent post.

    You can hide column M if you want.

  8. #8
    Forum Expert tigeravatar's Avatar
    Join Date
    03-25-2011
    Location
    Colorado, USA
    MS-Off Ver
    Excel 2003 - 2013
    Posts
    5,361

    Re: formula for strength of schedule?

    Its in the "Excel Programming / VBA / Macros" subforum, that's true. Generally speaking though it is better to avoid the use of VBA unless absolutely necessary. User's posted workbook is a .xlsx file which by definition has no macros, and there were already array formulas in it, so I just kept with formulas. If OP would like a VBA solution I can provide that as well, but it didn't (and still doesn't) seem to be necessary.

  9. #9
    Registered User
    Join Date
    07-22-2008
    Location
    auburn
    Posts
    74

    Re: formula for strength of schedule?

    Ok, wow... thank you so much for the help. Looks like it does what I need so I'm gonna mark the thread as solved and then see if I can decipher the formula. Would a macro be easier in your opinion? Thanks again for the help!

  10. #10
    Forum Expert tigeravatar's Avatar
    Join Date
    03-25-2011
    Location
    Colorado, USA
    MS-Off Ver
    Excel 2003 - 2013
    Posts
    5,361

    Re: formula for strength of schedule?

    A macro or UDF would certainly make it cleaner, and depending on your level of expertise with VBA it could certainly be easier. But then anytime you opened the workbook you'd be prompted to enable macros, or if you distributed the workbook others would get the prompt and would be very unlikely to know how to interact with macros at all.

    Still, if you'd like a VBA solution, let me know.

  11. #11
    Registered User
    Join Date
    07-22-2008
    Location
    auburn
    Posts
    74

    Re: formula for strength of schedule?

    I'd love to see a vba solution if not too much trouble... I'm the only one using the workbook so no issues there. Thanks!

  12. #12
    Forum Expert tigeravatar's Avatar
    Join Date
    03-25-2011
    Location
    Colorado, USA
    MS-Off Ver
    Excel 2003 - 2013
    Posts
    5,361

    Re: formula for strength of schedule?

    roasthawg,

    Attached is v3. It contains a button that will get calculate the opponent average. This is the macro the button is assigned to:
    Sub tgr()
        
        Dim rngTeams As Range
        Dim rngAway As Range
        Dim rngHome As Range
        Dim rngScores As Range
        Dim strOpponents As String
        Dim arrTeam(1 To 2) As String
        Dim arrData() As Double
        Dim DataIndex As Long
        Dim rIndex As Long
        Dim lRow As Long
        Dim i As Long
        
        Range("J2:K" & Rows.Count).ClearContents
        Set rngTeams = Range("B1:C1")
        Set rngScores = Range("D1:E1")
        ReDim arrData(1 To Cells(Rows.Count, "A").End(xlUp).Row, 1 To 2)
        
        For rIndex = 2 To Cells(Rows.Count, "A").End(xlUp).Row
            DataIndex = DataIndex + 1
            arrTeam(1) = Cells(rIndex, "B").Value
            arrTeam(2) = Cells(rIndex, "C").Value
            lRow = Evaluate("lookup(2,1/(A1:A" & rIndex - 1 & "<>" & Cells(rIndex, "A").Value2 & "),row(1:" & rIndex - 1 & "))")
            Set rngTeams = rngTeams.Resize(lRow)
            Set rngAway = rngTeams.Resize(, 1)
            Set rngHome = rngTeams.Offset(, 1).Resize(, 1)
            Set rngScores = rngScores.Resize(lRow)
            
            For i = 1 To 2
                If WorksheetFunction.CountIf(rngTeams, arrTeam(i)) > 0 Then
                    strOpponents = Join(Filter(Application.Transpose(Evaluate("If(" & rngAway.Address & "=""" & arrTeam(i) & """," & rngHome.Address & ",If(" & rngHome.Address & "=""" & arrTeam(i) & """," & rngAway.Address & "))")), False, False), """,""")
                    arrData(DataIndex, i) = Evaluate("Average(Index(AverageIf(" & rngTeams.Address & ",{""" & strOpponents & """}," & rngScores.Address & "),))")
                End If
            Next i
        Next rIndex
        
        Range("J2:K2").Resize(DataIndex).Value = arrData
        
        Set rngTeams = Nothing
        Set rngAway = Nothing
        Set rngHome = Nothing
        Set rngScores = Nothing
        Erase arrTeam
        Erase arrData
        
    End Sub

  13. #13
    Registered User
    Join Date
    07-22-2008
    Location
    auburn
    Posts
    74

    Re: formula for strength of schedule?

    Thank you so much for all the help... I'm gonna play around with both of these and see which solution I like better!

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1