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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
knielson
Frequent Visitor

How to calculate a win/loss streak with matchup data?

I have some match data with home team and away teams and the outcome of the match. 

How in power BI can I flag the current win and loss streak at that current point in the season.

The grey columns are what I'm looking to create.

For example, Utah wins 3 matches in a row but loses their 4th, so their highest win streak is 3 and their current loss streak is 1. 

 

knielson_2-1664833527878.png

 

 

 

1 ACCEPTED SOLUTION

Hi, @knielson ;

Try it.

Current Win Streak = 
var _max=CALCULATE(MAX('Table'[natch_ id]),FILTER('Table',[LTeam]=EARLIER('Table'[WTeam])&&[natch_ id]<EARLIER('Table'[natch_ id])))

var _min=CALCULATE(MIN('Table'[natch_ id]),FILTER('Table',[WTeam]=EARLIER('Table'[WTeam])&&[natch_ id]<EARLIER('Table'[natch_ id])))
var _value=IF(_max>=_min,_max,_min)
var _res= CALCULATE(COUNT('Table'[WTeam]),FILTER('Table',[natch_ id]>=_value&&[natch_ id]<=EARLIER('Table'[natch_ id])&&[WTeam]=EARLIER('Table'[WTeam])))
return _res
Current Loss Streak = 
var _max=CALCULATE(MAX('Table'[natch_ id]),FILTER('Table',[WTeam]=EARLIER('Table'[LTeam])&&[natch_ id]<EARLIER('Table'[natch_ id])))

var _min=CALCULATE(MIN('Table'[natch_ id]),FILTER('Table',[LTeam]=EARLIER('Table'[LTeam])&&[natch_ id]<EARLIER('Table'[natch_ id])))
var _value=IF(_max>=_min,_max,_min)
var _res= CALCULATE(COUNT('Table'[LTeam]),FILTER('Table',[natch_ id]>=_value&&[natch_ id]<=EARLIER('Table'[natch_ id])&&[LTeam]=EARLIER('Table'[LTeam])))
return _res


Best Regards,
Community Support Team _ Yalan Wu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

3 REPLIES 3
v-yalanwu-msft
Community Support
Community Support

Hi, @knielson ;

You could create a column by dax.

Current Win Streak = 
var _max=CALCULATE(MAX('Table'[natch_ id]),FILTER('Table',[LTeam]=EARLIER('Table'[WTeam])&&[natch_ id]<EARLIER('Table'[natch_ id])))

var _min=CALCULATE(MIN('Table'[natch_ id]),FILTER('Table',[WTeam]=EARLIER('Table'[WTeam])&&[natch_ id]<EARLIER('Table'[natch_ id])))
var _value=IF(_max>_min,_max,_min)
var _res= CALCULATE(COUNT('Table'[WTeam]),FILTER('Table',[natch_ id]>=_value&&[natch_ id]<=EARLIER('Table'[natch_ id])&&[WTeam]=EARLIER('Table'[WTeam])))
return _res
Current Loss Streak = 
var _max=CALCULATE(MAX('Table'[natch_ id]),FILTER('Table',[WTeam]=EARLIER('Table'[LTeam])&&[natch_ id]<EARLIER('Table'[natch_ id])))

var _min=CALCULATE(MIN('Table'[natch_ id]),FILTER('Table',[LTeam]=EARLIER('Table'[LTeam])&&[natch_ id]<EARLIER('Table'[natch_ id])))
var _value=IF(_max>_min,_max,_min)
var _res= CALCULATE(COUNT('Table'[LTeam]),FILTER('Table',[natch_ id]>=_value&&[natch_ id]<=EARLIER('Table'[natch_ id])&&[LTeam]=EARLIER('Table'[LTeam])))
return _res

The final show:

vyalanwumsft_0-1664850707442.png


Best Regards,
Community Support Team _ Yalan Wu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

This is great. I noticed that it doesn't reset the streak in the event of a tie. How could that be done?

Hi, @knielson ;

Try it.

Current Win Streak = 
var _max=CALCULATE(MAX('Table'[natch_ id]),FILTER('Table',[LTeam]=EARLIER('Table'[WTeam])&&[natch_ id]<EARLIER('Table'[natch_ id])))

var _min=CALCULATE(MIN('Table'[natch_ id]),FILTER('Table',[WTeam]=EARLIER('Table'[WTeam])&&[natch_ id]<EARLIER('Table'[natch_ id])))
var _value=IF(_max>=_min,_max,_min)
var _res= CALCULATE(COUNT('Table'[WTeam]),FILTER('Table',[natch_ id]>=_value&&[natch_ id]<=EARLIER('Table'[natch_ id])&&[WTeam]=EARLIER('Table'[WTeam])))
return _res
Current Loss Streak = 
var _max=CALCULATE(MAX('Table'[natch_ id]),FILTER('Table',[WTeam]=EARLIER('Table'[LTeam])&&[natch_ id]<EARLIER('Table'[natch_ id])))

var _min=CALCULATE(MIN('Table'[natch_ id]),FILTER('Table',[LTeam]=EARLIER('Table'[LTeam])&&[natch_ id]<EARLIER('Table'[natch_ id])))
var _value=IF(_max>=_min,_max,_min)
var _res= CALCULATE(COUNT('Table'[LTeam]),FILTER('Table',[natch_ id]>=_value&&[natch_ id]<=EARLIER('Table'[natch_ id])&&[LTeam]=EARLIER('Table'[LTeam])))
return _res


Best Regards,
Community Support Team _ Yalan Wu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Helpful resources

Announcements
RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

MayPowerBICarousel

Fabric Monthly Update - May 2024

Check out the May 2024 Fabric update to learn about new features.

LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.