Help with Current and highest streaks

Telman86

New Member
Joined
Dec 6, 2019
Messages
17
Office Version
  1. 2013
Platform
  1. Windows
Hi there,

I've just joined the forum and this is my first post. I've already spent quite a bit of time searching the net and this forum for a solution to my problem and can't find exactly what I'm looking for, so apologies if this has already been asked in the near past.

I am looking to calculate the longest and current streaks of Wins and Losses for my pool team players. The problem is that players may not play every week, but just because they don't play, this shouldn't interfere with their streaks. Therefore if a player wins two weeks running, then misses a week, and then wins the next two, his winning streak is still 4 over those five weeks. The streaks should only be restarted after a change in W or L.

I've set out an example below. This shows three players records over a 15 week period (my actual spreadsheet is for 36 weeks), although currently we have only played up to Week 11. Obviously W and L indicate a Win or Loss that week, whereas X indicates they did not play that week. All of these W's, L's and X's are automatically inserted into these cells by a formula dependent on data from elsewhere in my workbook. I am looking for formulas to go into columns Q, R & S, and I have indicated what the results should be.

Note that the array should always be B:P, i.e. all weeks up to the end of the season irrespective of whether the games have been played or not. Results are updated weekly and therefore the streaks need to automatically change as the data is populated into the new weeks.

Please also note that I am looking for formulas only. I can't do VBA!!

I hope this is clear, and I appreciate any help you can give.

A​
B​
C​
D​
E​
F​
G​
H​
I​
J​
K​
L​
M​
N​
O​
P​
Q​
R​
S​
1​
WEEK 1
WEEK 2
WEEK 3
WEEK 4
WEEK 5
WEEK 6
WEEK 7
WEEK 8
WEEK 9
WEEK 10
WEEK 11
WEEK 12WEEK 13WEEK 14WEEK 15
LONGEST W STREAK
LONGEST L STREAK
CURRENT STREAK
2​
John
W​
W​
X​
W​
W​
L​
X​
L​
W​
W​
W​
4
2
W3
3​
Peter
X​
W​
L​
L​
W​
X​
X​
W​
X​
W​
W​
4
2
W4
4​
George
X​
L​
L​
X​
L​
W​
X​
L​
X​
L​
X​
1
3
L2
 
Last edited by a moderator:
Are all your letters the same with no extra spaces?

If you have "W" in one cell and "W " (W with a space after it) the formula will not see them as the same and will not count it as a streak.
 
Upvote 0

Excel Facts

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"
OK, I've just cleared all the data from my cells B2:P5 and re-entered them. Now it works perfectly! That must have been the problem as I copied and pasted the table from Bo_Ry's post earlier rather than enter the data.

Thank you so much guys for all your help!
 
Upvote 0
No VBA, but how about a Power Query solution.

Book1
ABCDEFGHIJKLMNOPQRS
1NameWEEK 1WEEK 2WEEK 3WEEK 4WEEK 5WEEK 6WEEK 7WEEK 8WEEK 9WEEK 10WEEK 11WEEK 12WEEK 13WEEK 14WEEK 15Longest W StreakLongest L StreakCustom
2JohnWWXWWLXLWWWL42L1
3PeterXWLLWXXWXWWW52W5
4GeorgeXLLXLWXLXLXL13L3
Sheet1


Code for Longest Streak Table
Code:
let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    Index0 = Table.AddIndexColumn(Source, "Index", 0, 1),
    Reorder = Table.ReorderColumns(Index0,{"Name", "Index", "WEEK 1", "WEEK 2", "WEEK 3", "WEEK 4", "WEEK 5", "WEEK 6", "WEEK 7", "WEEK 8", "WEEK 9", "WEEK 10", "WEEK 11", "WEEK 12", "WEEK 13", "WEEK 14", "WEEK 15"}),
    Remove0 = Table.RemoveColumns(Reorder,{"Name"}),
    Unpivot = Table.UnpivotOtherColumns(Remove0, {"Index"}, "Attribute", "Value"),
    Index1 = Table.AddIndexColumn(Unpivot, "Index.1", 0, 1),
    FilterX = Table.SelectRows(Index1, each ([Value] <> "X")),
    Group0 = Table.Group(FilterX, {"Index", "Value"}, {{"Count",
        each Table.AddIndexColumn( Table.Sort(_, {{"Index.1", 0} } ) , "rowindexinsubset" ,1,1 ),
        type table}},GroupKind.Local),
    GetMax = Table.AddColumn(Group0, "Custom", each List.Max(Table.Column([Count],"rowindexinsubset"))),
    Group1 = Table.Group(GetMax, {"Index", "Value"}, {{"Count", each List.Max([Custom]), type number}}),
    Pivot = Table.Pivot(Group1, List.Distinct(Group1[Value]), "Value", "Count"),
    Rename = Table.RenameColumns(Pivot,{{"W", "Longest W Streak"}, {"L", "Longest L Streak"}}),
    Remove1 = Table.RemoveColumns(Rename,{"Index"})
in
    Remove1

Code for Latest Streak Table
Code:
let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    Index0 = Table.AddIndexColumn(Source, "Index", 0, 1),
    Reorder = Table.ReorderColumns(Index0,{"Name", "Index", "WEEK 1", "WEEK 2", "WEEK 3", "WEEK 4", "WEEK 5", "WEEK 6", "WEEK 7", "WEEK 8", "WEEK 9", "WEEK 10", "WEEK 11", "WEEK 12", "WEEK 13", "WEEK 14", "WEEK 15"}),
    Remove0 = Table.RemoveColumns(Reorder,{"Name"}),
    Unpivot = Table.UnpivotOtherColumns(Remove0, {"Index"}, "Attribute", "Value"),
    Index1 = Table.AddIndexColumn(Unpivot, "Index.1", 0, 1),
    FilterX = Table.SelectRows(Index1, each ([Value] <> "X")),
    Group0 = Table.Group(FilterX, {"Index", "Value"}, {{"Count",
        each Table.AddIndexColumn( Table.Sort(_, {{"Index.1", 0} } ) , "rowindexinsubset" ,1,1 ),
        type table}},GroupKind.Local),
    GetMax = Table.AddColumn(Group0, "Custom", each List.Max(Table.Column([Count],"rowindexinsubset"))),
    Index2 = Table.AddIndexColumn(GetMax, "Index.1", 0, 1),
    Group1 = Table.Group(Index2, {"Index"}, {{"Count", each _, type table}}),
    GetLast = Table.AddColumn(Group1, "Custom", each List.Last(Table.Column([Count],"Value")) & Text.From(List.Last(Table.Column([Count],"Custom")))),
    Remove1 = Table.RemoveColumns(GetLast,{"Index", "Count"}),
    Rename = Table.RenameColumns(Remove1,{{"Custom", "Current Streak"}})
in
    Rename
 
Upvote 0
Was able to consolidate the M code to just 1 table.

Code:
let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    Index0 = Table.AddIndexColumn(Source, "Index", 0, 1),
    Remove0 = Table.RemoveColumns(Index0,{"Name"}),
    Unpivot = Table.UnpivotOtherColumns(Remove0, {"Index"}, "Attribute", "Value"),
    FilterX = Table.SelectRows(Unpivot, each ([Value] = "L" or [Value] = "W")),
    Index1 = Table.AddIndexColumn(FilterX, "Index.1", 0, 1),
    Group0 = Table.Group(Index1, {"Index", "Value"}, {{"Count",
        each Table.AddIndexColumn( Table.Sort(_, {{"Index.1", 0} } ) , "subsetIndex" ,1,1 ),
        type table}},GroupKind.Local),
    GetMax = Table.AddColumn(Group0, "Custom", each List.Max(Table.Column([Count],"subsetIndex"))),
    Group1 = Table.Group(GetMax, {"Index"}, {{"Count", each _, type table}}),
    wStreak = Table.AddColumn(Group1, "Longest W Streak", each List.Max(Table.SelectRows([Count], each [Value]="W")[Custom])),
    lStreak = Table.AddColumn(wStreak, "Longest L Streak", each List.Max(Table.SelectRows([Count], each [Value]="L")[Custom])),
    LastStreak = Table.CombineColumns(Table.TransformColumnTypes(Table.ExpandRecordColumn(Table.AddColumn(lStreak, "Custom.1", each Table.Last([Count])), "Custom.1", {"Value", "Custom"}, {"Value", "Custom"}), {{"Custom", type text}}, "en-US"),{"Value", "Custom"},Combiner.CombineTextByDelimiter("", QuoteStyle.None),"Last Streak"),
    Remove1 = Table.RemoveColumns(LastStreak,{"Index", "Count"})
in
    Remove1

Book1
ABCDEFGHIJKLMNOPQRS
1NameWEEK 1WEEK 2WEEK 3WEEK 4WEEK 5WEEK 6WEEK 7WEEK 8WEEK 9WEEK 10WEEK 11WEEK 12WEEK 13WEEK 14WEEK 15Longest W StreakLongest L StreakLast Streak
2AlanWWWWXWLLLLWW54W2
3BarbLXXLWLWXLLLWL13L1
4CainXLLWXWWLXLLWL33L1
5DanaWLLLLWLXLWWW34W3
6EricWLWLXWXLWLLWWW32W3
7FranXLLWLWXLWLW12W1
8GaryLLLLLXXXWWXLLLL25L4
9HanaLLXXWXWXXWXWWXW52W5
10IvanWWLWLLWWLXWL22L1
11JaneLWLWXWWXLLXWWX32W2
12KentWLLLWLWWLXXLX23L2
13LeahXWWWXXXLWWXW31W3
14MarkWWWWWLLWWXLLXW52W1
15NinaLLLLXLLWXLWLLXL16L3
16RobLWLLWWWWXWWXW72W7
Sheet1
 
Upvote 0
Hello, hope it's fine if I just reuse this topic. Very similar question to OPs, answers here have been excellent but I lost almost the entire afternoon today trying to dissect given formulas to get what I want so I figured it's best to just create an account and ask!

So I'm looking to get formulas for current winning, unbeaten, winless and losing streak; any ideas? Thanks a lot!

2021-01-05.png
 
Upvote 0
Welcome to the MrExcel forum!

It's ok to add to an existing thread, in that there's no rule against it, but you run the risk that no one will notice your post. It's usually best to open a new thread with a question. Also, check out the XL2BB tool. There's a link in my signature, and in the reply box. It makes it so people can copy your sample sheet directly from the post, and then they won't have to retype everything which is the case if you only post a picture. You're more likely to get more and faster help if you do. It's what I use below.

Given that, consider this:

Book1
ABCDEFGHIJKLMNOPQRSTUVWXYZAAABACADAEAFAGAHAIAJAKALAMANAOAPAQARASAT
1
2TOTAL123456789101112131415161718192021222324252627282930313233343536WWDDLLWWDDLL
31Team1WDWDLDWDLWWWWWLWWWD0410
47Team2LDLDWWLDLDWWLLLDWWL0011
56Team3
62Team4
75Team5
89Team6
93Team7
104Team8
118Team9
1210Team10
13LongestCurrent
Sheet4
Cell Formulas
RangeFormula
AQ3:AQ4AQ3=COUNTIF(INDEX(3:3,AGGREGATE(14,6,COLUMN($C3:$AL3)/(($C3:$AL3="D")+($C3:$AL3="L")+($C$2:$AL$2=1)),1)):$AL3,"W")
AR3:AR4AR3=SUM(COUNTIF(INDEX(3:3,AGGREGATE(14,6,COLUMN($C3:$AL3)/(($C3:$AL3="L")+($C$2:$AL$2=1)),1)):$AL3,{"W","D"}))
AS3:AS4AS3=SUM(COUNTIF(INDEX(3:3,AGGREGATE(14,6,COLUMN($C3:$AL3)/(($C3:$AL3="W")+($C$2:$AL$2=1)),1)):$AL3,{"L","D"}))
AT3:AT4AT3=COUNTIF(INDEX(3:3,AGGREGATE(14,6,COLUMN($C3:$AL3)/(($C3:$AL3="D")+($C3:$AL3="W")+($C$2:$AL$2=1)),1)):$AL3,"L")


This should do what you want. I only typed in a couple of test rows, so make sure it works on the rest of your data.

Also, I wasn't sure what to do with the blank spaces in column R.

Good luck!
 
Upvote 0
Thanks Eric, it works like a charm!

Yeah that's a great tool, goot to know for next time.

The two blank spaces are from a postponed game which is yet to be played
 
Upvote 0
Doing the whole thing, longest and current, using Power Query.

Streaky.xlsx
BCDEFGHIJKLMNOPQRSTUVWXYZAAABACADAEAFAGAHAIAJAKALAMANAOAPAQARASAT
2Total123456789101112131415161718192021222324252627282930313233343536W (Long)WD (Long)LD (Long)L (Long)W (Current)WD (Current)WL (Current)L (Current)
3Team 1DLWDWWWDWLWDDLDLLLW37731100
4Team 2DDLDWWDWWWLDDDDLDDW37811300
5Team 3LWLDLLLLWDWWLWWLLDW24641200
6Team 4DDLDDDLLWDDLLLWWWWD45830510
7Team 5DDDLDLWWDLDWWDDDLLW26621100
8Team 6WDDWDLWLDLWWWLLLWDL35330021
9Team 7WDWDDLDLDWWDLWDDLDW25611200
10Team 8LDWDLDWDWWWDWLWDLLW38321100
11Team 9LDLLLDWWLWLWWWWWLWW55632200
12Team 10DDLWDDLDLDWDLDLLWLL13620022
Sheet1


Power Query:
let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    Unpivot = Table.UnpivotOtherColumns(Source, {"Total"}, "Attribute", "Value"),
    Types = Table.TransformColumnTypes(Unpivot,{{"Total", type text}, {"Value", type text}, {"Attribute", Int64.Type}}),
    DtoW = Table.DuplicateColumn(Types, "Value", "WD"),
    DtoL = Table.DuplicateColumn(DtoW, "Value", "LD"),
    ReplaceW = Table.ReplaceValue(DtoL,"D","W",Replacer.ReplaceText,{"WD"}),
    ReplaceL = Table.ReplaceValue(ReplaceW,"D","L",Replacer.ReplaceText,{"LD"}),
    GroupTeam = Table.Group(ReplaceL, {"Total"}, {{"Count", each _, type table}}),
    WL = Table.TransformColumns(GroupTeam, {{"Count", (tbl)=> Table.Group(tbl,"Value",{"Total", each Table.RowCount(_)},GroupKind.Local)}}),
    GroupWL = Table.TransformColumns(WL, {{"Count", (tbl)=> Table.Group(tbl,"Value",{"Max", each List.Max(_[Total])})}}),
    WD = Table.TransformColumns(GroupTeam, {{"Count", (tbl)=> Table.Group(tbl,"WD",{"Total", each Table.RowCount(_)},GroupKind.Local)}}),
    GroupWD = Table.TransformColumns(WD, {{"Count", (tbl)=> Table.Group(tbl,"WD",{"Max", each List.Max(_[Total])})}}),
    LD = Table.TransformColumns(GroupTeam, {{"Count", (tbl)=> Table.Group(tbl,"LD",{"Total", each Table.RowCount(_)},GroupKind.Local)}}),
    GroupLD = Table.TransformColumns(LD, {{"Count", (tbl)=> Table.Group(tbl,"LD",{"Max", each List.Max(_[Total])})}}),
    Index = Table.AddIndexColumn(GroupLD, "Index", 0, 1),
    WinsLong = Table.AddColumn(Index, "W (Long)", each Table.SelectRows(GroupWL[Count]{[Index]}, each _[Value] = "W"){0}[Max]),
    LossLong = Table.AddColumn(WinsLong, "L (Long)", each Table.SelectRows(GroupWL[Count]{[Index]}, each _[Value] = "L"){0}[Max]),
    uLong = Table.AddColumn(LossLong, "WD (Long)", each Table.SelectRows(GroupWD[Count]{[Index]}, each _[WD] = "W"){0}[Max]),
    bLong = Table.AddColumn(uLong, "LD (Long)", each Table.SelectRows(GroupLD[Count]{[Index]}, each _[LD] = "L"){0}[Max]),
    wCurrent = Table.AddColumn(bLong, "W (Current)", (tbl)=> Table.TransformColumns(WL,{{"Count", each Table.SelectRows(Table.LastN(_,1), (t)=> t[Value]="W")}}){tbl[Index]}[Count][Total]{0}),
    lCurrent = Table.AddColumn(wCurrent, "L (Current)", (tbl)=> Table.TransformColumns(WL,{{"Count", each Table.SelectRows(Table.LastN(_,1), (t)=> t[Value]="L")}}){tbl[Index]}[Count][Total]{0}),
    wdCurrent = Table.AddColumn(lCurrent, "WD (Current)", (tbl)=> Table.TransformColumns(WD,{{"Count", each Table.SelectRows(Table.LastN(_,1), (t)=> t[WD]="W")}}){tbl[Index]}[Count][Total]{0}),
    wlCurrent = Table.AddColumn(wdCurrent, "WL (Current)", (tbl)=> Table.TransformColumns(LD,{{"Count", each Table.SelectRows(Table.LastN(_,1), (t)=> t[LD]="L")}}){tbl[Index]}[Count][Total]{0}),
    REW = Table.ReplaceErrorValues(wlCurrent, {{"W (Current)", 0}}),
    REL = Table.ReplaceErrorValues(REW, {{"L (Current)", 0}}),
    REWD = Table.ReplaceErrorValues(REL, {{"WD (Current)", 0}}),
    REWL = Table.ReplaceErrorValues(REWD, {{"WL (Current)", 0}}),
    Reorder = Table.ReorderColumns(REWL,{"Total", "Count", "Index", "W (Long)", "WD (Long)", "LD (Long)", "L (Long)", "W (Current)", "WD (Current)", "WL (Current)", "L (Current)"}),
    Select = Table.SelectColumns(Reorder,{"W (Long)", "WD (Long)", "LD (Long)", "L (Long)", "W (Current)", "WD (Current)", "WL (Current)", "L (Current)"})
in
    Select
 
Upvote 0

Forum statistics

Threads
1,214,599
Messages
6,120,453
Members
448,967
Latest member
grijken

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