The below is put together with a view to amending as little as possible regards your "source" data sheet - as such things are quite complex.
First, create some named ranges... with League!A2 the active cell add the following Defined Names:
Name: _Results
RefersTo: =Results!$A$2:INDEX(Results!$H:$H,MATCH(9.99E+307,Results!$D:$D))
Name: _ResultsFinal
RefersTo: =INDEX(_Results,$R2,1):INDEX(_Results,ROWS(_Results),COLUMNS(_Results))
With the above inserted we can then add some formulae to calculate streak and Last "n" performance.
First we can add a couple of helper cells to assist our calcs...
Q1: Last
Q2:
=IF(LOOKUP(2,1/((INDEX(_Results,0,7)=$B2)+(INDEX(_Results,0,2)=$B2)),SIGN((INDEX(_Results,0,5)+INDEX(_Results,0,6))-(INDEX(_Results,0,4)+INDEX(_Results,0,3)))=LOOKUP(INDEX(_Results,0,7)=$B2,{FALSE,TRUE},{-1,1})),1,-1)
apply custom format to Q2 of "Win";"Loss"
copied down to Q31
R1: Start Ln
R2:
=IF($C2<0+SUBSTITUTE($O$1,"L",""),1,LARGE(IF(ISNUMBER(SEARCH("^"&$B2&"^","^"&INDEX(_Results,0,2)&"^"&INDEX(_Results,0,7)&"^")),ROW(_Results)-ROW(INDEX(_Results,1,1))+1),MIN(SUBSTITUTE($O$1,"L",""),$C2)))
confirmed with CTRL + SHIFT + ENTER
copied down to R31
In simplistic terms:
- Col Q tells us the last result for the given team be it a Win (1) or a Loss (-1)
- Col R establishes from which row of results data set we should begin to look for results (ie discounting those prior to last "n" fixtures)
Then...
L"n" performance:
O2:
=SUM(IF((INDEX(_ResultsFinal,0,7)=$B2)+(INDEX(_ResultsFinal,0,2)=$B2),IF((INDEX(_ResultsFinal,0,5)+INDEX(_ResultsFinal,0,6))>(INDEX(_ResultsFinal,0,4)+INDEX(_ResultsFinal,0,3)),IF(INDEX(_ResultsFinal,0,7)=$B2,1,1/24),IF(INDEX(_ResultsFinal,0,7)=$B2,1/24,1))))
confirmed with CTRL + SHIFT + ENTER
apply custom format of: d-h
copied down to O31
Streak
P2:
=MAX(FREQUENCY(IF((INDEX(_Results,0,7)=$B2)+(INDEX(_Results,0,2)=$B2),IF((SIGN(((INDEX(_Results,0,5)+INDEX(_Results,0,6))-(INDEX(_Results,0,4)+INDEX(_Results,0,3))))=IF(INDEX(_Results,0,7)=$B2,$Q2,-$Q2)),ROW(_Results))),IF((INDEX(_Results,0,7)=$B2)+(INDEX(_Results,0,2)=$B2),IF((SIGN(((INDEX(_Results,0,5)+INDEX(_Results,0,6))-(INDEX(_Results,0,4)+INDEX(_Results,0,3))))<>IF(INDEX(_Results,0,7)=$B2,$Q2,-$Q2)),ROW(_Results)))))*$Q2
confirmed with CTRL + SHIFT + ENTER
apply Custom Format of "W"0;"L"0
copied down to P31
NOTES:
-- Should you modify O1 from L10 to L5 for ex. the calculations will adapt automatically.
-- Streak does not rely on L"n" - it will use all fixtures to determine the streak.
I have attached a working sample of the above.
Bookmarks