<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Count streak? (consecutive values) in DAX Commands and Tips</title>
    <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Count-streak-consecutive-values/m-p/722884#M1441</link>
    <description>&lt;P&gt;Hey,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;as I already mentioned I created the sequence using Power Query, as it performs much better even if it requires some "tweeking" of M code, but nevertheless, it's quite fast.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I started with the transform "Group by" in Power Query:&lt;/P&gt;
&lt;P&gt;&lt;img /&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Not it's necessary to tweek the autogenerated M code, for this switch to the Advanced Editor.&lt;BR /&gt;Be aware that the grouping editor can not be opened again, after the M code is adjusted, for this you might want to copy the original line and just comment out the line, use 2 slashes for commenting //&lt;BR /&gt;Discover the M function Table.Group and format code similar to this:&lt;/P&gt;
&lt;PRE&gt;#"Grouped Rows" = 
            Table.Group(#"Filtered Rows", {"Team", "Result"}, {{"AllRows", 
            each _, 
            type table [Date=date, Team=text, Result=text, Streak=number, Latest  Streak=text, Latest Streak Count=number]}})&lt;/PRE&gt;
&lt;P&gt;In the second replace the _ with this:&lt;/P&gt;
&lt;PRE&gt;Table.AddIndexColumn( Table.Sort(_, {{"Date", 0} } ) , "rowindexinsubset" ,1,1 )&lt;/PRE&gt;
&lt;P&gt;In the third line remove the record (everything between the square bracketes) and the brackets itself.&lt;/P&gt;
&lt;P&gt;After the removal, insert this:&lt;/P&gt;
&lt;PRE&gt;GroupKind.Local&lt;/PRE&gt;
&lt;P&gt;Finally it should look like this:&lt;/P&gt;
&lt;PRE&gt;#"Grouped Rows" = 
            Table.Group(#"Filtered Rows", {"Team", "Result"}, {{"AllRows", 
            each Table.AddIndexColumn( Table.Sort(_, {{"Date", 0} } ) , "rowindexinsubset" ,1,1 ), 
            type table }} , GroupKind.Local)&lt;/PRE&gt;
&lt;P&gt;After this I expanded the table:&lt;/P&gt;
&lt;P&gt;&lt;img /&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;After this I created two calculated columns like so:&lt;/P&gt;
&lt;PRE&gt;c latest streak count = 
var _team = 'TeamResults'[Team]
var maxDate = CALCULATE(MAX('TeamResults'[Date]) , FILTER(ALL(TeamResults) , 'TeamResults'[Team] = _team))
var lateststreakcount = LOOKUPVALUE('TeamResults'[rowindexinsubset] , TeamResults[Team] , _team , TeamResults[Date] , maxDate)
return
IF(AND('TeamResults'[Team] = _team , 'TeamResults'[Date] = maxDate)
    , lateststreakcount
    , BLANK()
)&lt;/PRE&gt;
&lt;P&gt;and this&lt;/P&gt;
&lt;PRE&gt;c latest streak = 
var _team = 'TeamResults'[Team]
var maxDate = CALCULATE(MAX('TeamResults'[Date]) , FILTER(ALL(TeamResults) , 'TeamResults'[Team] = _team))
var lateststreak = LOOKUPVALUE('TeamResults'[Result] , TeamResults[Team] , _team , TeamResults[Date] , maxDate)
return
IF(AND('TeamResults'[Team] = _team , 'TeamResults'[Date] = maxDate)
    , lateststreak
    , BLANK()
)&lt;/PRE&gt;
&lt;P&gt;After all this the table will look like this, the result matches your expected results at least as far as I understand the data:&lt;/P&gt;
&lt;P&gt;&lt;img /&gt;&lt;/P&gt;
&lt;P&gt;Here you will find a &lt;A href="https://tommartens-my.sharepoint.com/:u:/g/personal/tom_minceddata_com/EdqMiR8qhYVLmvQ2NZoxgnIBPmEzhbqA5zPxhQUeSJlsKw?e=FsUwCI" target="_self"&gt;pbix file&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Regards,&lt;BR /&gt;Tom&lt;/P&gt;</description>
    <pubDate>Mon, 24 Jun 2019 19:57:08 GMT</pubDate>
    <dc:creator>TomMartens</dc:creator>
    <dc:date>2019-06-24T19:57:08Z</dc:date>
    <item>
      <title>Count streak? (consecutive values)</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Count-streak-consecutive-values/m-p/722641#M1431</link>
      <description>&lt;P&gt;See below my team data:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;img /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want to capture:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The streak - so the count of consecutive Win/Lose/Draw.&lt;/P&gt;&lt;P&gt;The latest streak - what's the current streak?&lt;/P&gt;&lt;P&gt;The latest streak count - the count of the latest streak&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is this possible with DAX?&lt;/P&gt;</description>
      <pubDate>Mon, 24 Jun 2019 14:17:23 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Count-streak-consecutive-values/m-p/722641#M1431</guid>
      <dc:creator>thisisausername</dc:creator>
      <dc:date>2019-06-24T14:17:23Z</dc:date>
    </item>
    <item>
      <title>Re: Count streak? (consecutive values)</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Count-streak-consecutive-values/m-p/722686#M1432</link>
      <description>&lt;P&gt;Hey,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;this is possible with DAX, but I would recommend to consider using Power Query to create the sequence of consecutive streaks per team.&lt;/P&gt;
&lt;P&gt;My assupmtion: there is just one result per team per day?!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Please create a pbix and or xlsx with sample data, upload the files to onedrive or dropbox and share the link.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Regards,&lt;/P&gt;
&lt;P&gt;Tom&lt;/P&gt;</description>
      <pubDate>Mon, 24 Jun 2019 15:02:10 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Count-streak-consecutive-values/m-p/722686#M1432</guid>
      <dc:creator>TomMartens</dc:creator>
      <dc:date>2019-06-24T15:02:10Z</dc:date>
    </item>
    <item>
      <title>Re: Count streak? (consecutive values)</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Count-streak-consecutive-values/m-p/722763#M1438</link>
      <description>&lt;P&gt;Hi Tom,&lt;BR /&gt;&lt;BR /&gt;Correct - for each team, there is only one result per week commencing date.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;XLSX is here:&amp;nbsp;&lt;A href="https://www.dropbox.com/s/kaqy9uy1s2ytd05/TeamResults.xlsx?dl=0" target="_blank"&gt;https://www.dropbox.com/s/kaqy9uy1s2ytd05/TeamResults.xlsx?dl=0&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you&lt;/P&gt;</description>
      <pubDate>Mon, 24 Jun 2019 16:15:18 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Count-streak-consecutive-values/m-p/722763#M1438</guid>
      <dc:creator>thisisausername</dc:creator>
      <dc:date>2019-06-24T16:15:18Z</dc:date>
    </item>
    <item>
      <title>Re: Count streak? (consecutive values)</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Count-streak-consecutive-values/m-p/722884#M1441</link>
      <description>&lt;P&gt;Hey,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;as I already mentioned I created the sequence using Power Query, as it performs much better even if it requires some "tweeking" of M code, but nevertheless, it's quite fast.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I started with the transform "Group by" in Power Query:&lt;/P&gt;
&lt;P&gt;&lt;img /&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Not it's necessary to tweek the autogenerated M code, for this switch to the Advanced Editor.&lt;BR /&gt;Be aware that the grouping editor can not be opened again, after the M code is adjusted, for this you might want to copy the original line and just comment out the line, use 2 slashes for commenting //&lt;BR /&gt;Discover the M function Table.Group and format code similar to this:&lt;/P&gt;
&lt;PRE&gt;#"Grouped Rows" = 
            Table.Group(#"Filtered Rows", {"Team", "Result"}, {{"AllRows", 
            each _, 
            type table [Date=date, Team=text, Result=text, Streak=number, Latest  Streak=text, Latest Streak Count=number]}})&lt;/PRE&gt;
&lt;P&gt;In the second replace the _ with this:&lt;/P&gt;
&lt;PRE&gt;Table.AddIndexColumn( Table.Sort(_, {{"Date", 0} } ) , "rowindexinsubset" ,1,1 )&lt;/PRE&gt;
&lt;P&gt;In the third line remove the record (everything between the square bracketes) and the brackets itself.&lt;/P&gt;
&lt;P&gt;After the removal, insert this:&lt;/P&gt;
&lt;PRE&gt;GroupKind.Local&lt;/PRE&gt;
&lt;P&gt;Finally it should look like this:&lt;/P&gt;
&lt;PRE&gt;#"Grouped Rows" = 
            Table.Group(#"Filtered Rows", {"Team", "Result"}, {{"AllRows", 
            each Table.AddIndexColumn( Table.Sort(_, {{"Date", 0} } ) , "rowindexinsubset" ,1,1 ), 
            type table }} , GroupKind.Local)&lt;/PRE&gt;
&lt;P&gt;After this I expanded the table:&lt;/P&gt;
&lt;P&gt;&lt;img /&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;After this I created two calculated columns like so:&lt;/P&gt;
&lt;PRE&gt;c latest streak count = 
var _team = 'TeamResults'[Team]
var maxDate = CALCULATE(MAX('TeamResults'[Date]) , FILTER(ALL(TeamResults) , 'TeamResults'[Team] = _team))
var lateststreakcount = LOOKUPVALUE('TeamResults'[rowindexinsubset] , TeamResults[Team] , _team , TeamResults[Date] , maxDate)
return
IF(AND('TeamResults'[Team] = _team , 'TeamResults'[Date] = maxDate)
    , lateststreakcount
    , BLANK()
)&lt;/PRE&gt;
&lt;P&gt;and this&lt;/P&gt;
&lt;PRE&gt;c latest streak = 
var _team = 'TeamResults'[Team]
var maxDate = CALCULATE(MAX('TeamResults'[Date]) , FILTER(ALL(TeamResults) , 'TeamResults'[Team] = _team))
var lateststreak = LOOKUPVALUE('TeamResults'[Result] , TeamResults[Team] , _team , TeamResults[Date] , maxDate)
return
IF(AND('TeamResults'[Team] = _team , 'TeamResults'[Date] = maxDate)
    , lateststreak
    , BLANK()
)&lt;/PRE&gt;
&lt;P&gt;After all this the table will look like this, the result matches your expected results at least as far as I understand the data:&lt;/P&gt;
&lt;P&gt;&lt;img /&gt;&lt;/P&gt;
&lt;P&gt;Here you will find a &lt;A href="https://tommartens-my.sharepoint.com/:u:/g/personal/tom_minceddata_com/EdqMiR8qhYVLmvQ2NZoxgnIBPmEzhbqA5zPxhQUeSJlsKw?e=FsUwCI" target="_self"&gt;pbix file&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Regards,&lt;BR /&gt;Tom&lt;/P&gt;</description>
      <pubDate>Mon, 24 Jun 2019 19:57:08 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Count-streak-consecutive-values/m-p/722884#M1441</guid>
      <dc:creator>TomMartens</dc:creator>
      <dc:date>2019-06-24T19:57:08Z</dc:date>
    </item>
    <item>
      <title>Re: Count streak? (consecutive values)</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Count-streak-consecutive-values/m-p/3693059#M143564</link>
      <description>&lt;P&gt;Hi Tom,&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am trying to follow these instructions for a similar need, but at the point of creating the two calculated fields I get the following error: "A table of multiple values was suppied where a single value was expected".&amp;nbsp; Are you able to suggest any corrections?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 12 Feb 2024 00:22:11 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Count-streak-consecutive-values/m-p/3693059#M143564</guid>
      <dc:creator>DSharbaugh</dc:creator>
      <dc:date>2024-02-12T00:22:11Z</dc:date>
    </item>
  </channel>
</rss>

