Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.
I have this table that has the information about the result of an event that can be "Won" and "Lost".
I would like a measure in DAX that calculates the number of consecutive times that "Won" is achieved without "Lost" appearing.
In this example it would be 4
Result |
Won |
Won |
Lost |
Won |
Lost |
Won |
Won |
Won |
Won |
Lost |
Lost |
Solved! Go to Solution.
Hi @Matthew9900 ,
I suggest you to add an index column and then add a group column in Power Query Editor.
List.Count(
let
_Index = [Index]
in
Table.SelectRows(#"Added Index",each [Index]<=_Index and [Result] = "Lost")[Result])
New Table:
Measure:
Consecutive win times =
VAR _SUMMARIZE =
SUMMARIZE (
FILTER ( 'Table', 'Table'[Result] = "Won" ),
'Table'[Group],
"Count", COUNT ( 'Table'[Index] )
)
RETURN
MAXX ( _SUMMARIZE, [Count] )
Result is as below.
Best Regards,
Rico Zhou
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Hi @Matthew9900
The solution given by @v-rzhou-msft is great.
You can also do the 1st step with DAX as follows -create a Group COLUMN
Hi @Matthew9900 ,
I suggest you to add an index column and then add a group column in Power Query Editor.
List.Count(
let
_Index = [Index]
in
Table.SelectRows(#"Added Index",each [Index]<=_Index and [Result] = "Lost")[Result])
New Table:
Measure:
Consecutive win times =
VAR _SUMMARIZE =
SUMMARIZE (
FILTER ( 'Table', 'Table'[Result] = "Won" ),
'Table'[Group],
"Count", COUNT ( 'Table'[Index] )
)
RETURN
MAXX ( _SUMMARIZE, [Count] )
Result is as below.
Best Regards,
Rico Zhou
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Based on your description, I created data to reproduce your scenario. The pbix file is attached in the end.
https://1drv.ms/u/s!AiUZ0Ws7G26Rhxiw0R7SH-9Yuurj?e=cK4yaP
Please check https://community.powerbi.com/t5/DAX-Commands-and-Tips/DAX-How-to-Count-the-Consecutive-Occurrences/...
I also tried it with this DAX function (hopefully easier)
Step1
Regards,
Ritesh
Thank you very much ribisht17
The solution is working but it is not adequate. The objective of this measurement is to find the longest winning streak, in this example it is giving me 6, but the correct answer should be 4.
That part is there in the link that I shared with you
Regards,
Ritesh
Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City
Check out the April 2024 Power BI update to learn about new features.
User | Count |
---|---|
104 | |
95 | |
80 | |
67 | |
62 |
User | Count |
---|---|
146 | |
110 | |
107 | |
86 | |
63 |