Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

We've captured the moments from FabCon & SQLCon that everyone is talking about, and we are bringing them to the community, live and on-demand. Starts on April 14th. Register now

Reply
thisisausername
Helper II
Helper II

Count streak? (consecutive values)

See below my team data:

 

Streak_.png

 

I want to capture:

 

The streak - so the count of consecutive Win/Lose/Draw.

The latest streak - what's the current streak?

The latest streak count - the count of the latest streak

 

Is this possible with DAX?

4 REPLIES 4
TomMartens
Super User
Super User

Hey,

 

this is possible with DAX, but I would recommend to consider using Power Query to create the sequence of consecutive streaks per team.

My assupmtion: there is just one result per team per day?!

 

Please create a pbix and or xlsx with sample data, upload the files to onedrive or dropbox and share the link.

 

Regards,

Tom



Did I answer your question? Mark my post as a solution, this will help others!

Proud to be a Super User!
I accept Kudos 😉
Hamburg, Germany

Hi Tom,

Correct - for each team, there is only one result per week commencing date.

 

XLSX is here: https://www.dropbox.com/s/kaqy9uy1s2ytd05/TeamResults.xlsx?dl=0

 

Thank you

Hey,

 

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.

 

I started with the transform "Group by" in Power Query:

image.png

 

Not it's necessary to tweek the autogenerated M code, for this switch to the Advanced Editor.
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 //
Discover the M function Table.Group and format code similar to this:

#"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]}})

In the second replace the _ with this:

Table.AddIndexColumn( Table.Sort(_, {{"Date", 0} } ) , "rowindexinsubset" ,1,1 )

In the third line remove the record (everything between the square bracketes) and the brackets itself.

After the removal, insert this:

GroupKind.Local

Finally it should look like this:

#"Grouped Rows" = 
            Table.Group(#"Filtered Rows", {"Team", "Result"}, {{"AllRows", 
            each Table.AddIndexColumn( Table.Sort(_, {{"Date", 0} } ) , "rowindexinsubset" ,1,1 ), 
            type table }} , GroupKind.Local)

After this I expanded the table:

image.png

 

After this I created two calculated columns like so:

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()
)

and this

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()
)

After all this the table will look like this, the result matches your expected results at least as far as I understand the data:

image.png

Here you will find a pbix file

 

Regards,
Tom



Did I answer your question? Mark my post as a solution, this will help others!

Proud to be a Super User!
I accept Kudos 😉
Hamburg, Germany

Hi Tom,  

 

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".  Are you able to suggest any corrections?

 

Helpful resources

Announcements
New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

Join our Fabric User Panel

Join our Fabric User Panel

Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.

March Power BI Update Carousel

Power BI Community Update - March 2026

Check out the March 2026 Power BI update to learn about new features.