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

A new Data Days event is coming soon! This time we’re going bigger than ever. Fabric, Power BI, SQL, AI and more. Don't miss out.

Reply
BigPatJennings
Frequent Visitor

longest streak, incl and excl gaps

Hi,

 I've searched for 'streaks' in this forum but can't see something that fits the bill. I have data where I need to find the longest 'yes'  streaks, where there are three outcomes: yes, no or blank. I need two measures - one that counts blanks as 'no', and one that ignores blanks.

I've attached a sample pbix (and year being text is not a mistake, due to the data I'm dealing with. It's possible that the date could be 2019.7, for example)

The data looks like this, and I've attached a pbix with the desired result.

Thanks in anticipation !

 

https://drive.google.com/file/d/1s2RmK95cdG0kiAzldhzOV0jznNYHmzX3

YearShiftNameSuccess

20201AaronY
20202AaronY
20203AaronN
20211AaronY
20212AaronY
20221AaronY
20222AaronY
20223AaronY
20224AaronY
20201BettyY
20202Betty 
20203BettyY
20211BettyY
20212BettyY
20221BettyN
20222BettyY
20223BettyY
20224BettyN
20201CharlieY
20202Charlie 
20203CharlieY
20211CharlieN
20212CharlieN
20221CharlieN
20222CharlieN
20223CharlieN
20224CharlieN

 

Desired result 1 is: Aaron 6, Betty 3, Charlie 1 (blanks count as a 'no')

Desired result 2 is: Aaron 6, Betty 4, Charlie 2 (blanks ignored)

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @BigPatJennings ,

Please refer to my pbix file to see if it helps you.

Create 2 columns.

value_1re = var _1= CALCULATE(MIN('Table'[Success]),FILTER('Table','Table'[Index]=EARLIER('Table'[Index])+1&&'Table'[Name]=EARLIER('Table'[Name])&&'Table'[Success]="Y"))
return 
IF('Table'[Success]=_1,1,BLANK())
value_2re = 

var aa = CALCULATE(MIN('Table'[Index]),FILTER(ALLEXCEPT('Table','Table'[name]),'Table'[Index]>=EARLIER('Table'[Index])&&'Table'[Success]="N"))

var bb = CALCULATE(MAX('Table'[Index]),FILTER(ALLEXCEPT('Table','Table'[name]),'Table'[Index]>=EARLIER('Table'[Index])&&'Table'[Success]<>"N"))

return 

IF(ISBLANK(aa),bb,aa)

Then create measures.

value1 = var _1= CALCULATE(COUNT('Table'[value_1re]),FILTER(ALL('Table'),'Table'[Name]=SELECTEDVALUE('Table'[Name])&&'Table'[value_1re]<>BLANK()))
return 
IF(_1=BLANK(),_1+1,_1)
value2 = var _1= CALCULATE(COUNT('Table'[Index]),FILTER(ALL('Table'),'Table'[value_2re]=SELECTEDVALUE('Table'[value_2re])&&'Table'[Name]=SELECTEDVALUE('Table'[Name])&&'Table'[Success]="Y"))
return 
_1
Measure 2 = MAXX(FILTER(ALL('Table'),'Table'[Name]=SELECTEDVALUE('Table'[Name])),[value2])

vpollymsft_0-1666688395079.png

Best Regards

Community Support Team _ Polly

 

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

5 REPLIES 5
Anonymous
Not applicable

Hi @BigPatJennings ,

Why Desired result 1 is: Aaron 6, Betty 3, Charlie 1 . How to get the result? I cannot get the pbix file.

 

Could you please provide the pbix file without privacy information and desired output with more details(Explain to me why  got 6, 3, 1 respectively).

 

Thank you!

 

Best Regards

Community Support Team _ Polly

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Hi @Anonymous ,

If you make the table readble, you'll see the results are

Aaron YYNYYYYYY (6 Y's is the longest streak)

Betty  Y_YYYNYYN (3 Y's is the longest, 4 Y's is the longest if you exclude the break)

Charlie Y_YNNNNNN (1 longest, 2 if you exclude the break)

I've edited the link to hopefully allow access

https://drive.google.com/file/d/1s2RmK95cdG0kiAzldhzOV0jznNYHmzX3

Anonymous
Not applicable

Hi @BigPatJennings ,

Please refer to my pbix file to see if it helps you.

Create 2 columns.

value_1re = var _1= CALCULATE(MIN('Table'[Success]),FILTER('Table','Table'[Index]=EARLIER('Table'[Index])+1&&'Table'[Name]=EARLIER('Table'[Name])&&'Table'[Success]="Y"))
return 
IF('Table'[Success]=_1,1,BLANK())
value_2re = 

var aa = CALCULATE(MIN('Table'[Index]),FILTER(ALLEXCEPT('Table','Table'[name]),'Table'[Index]>=EARLIER('Table'[Index])&&'Table'[Success]="N"))

var bb = CALCULATE(MAX('Table'[Index]),FILTER(ALLEXCEPT('Table','Table'[name]),'Table'[Index]>=EARLIER('Table'[Index])&&'Table'[Success]<>"N"))

return 

IF(ISBLANK(aa),bb,aa)

Then create measures.

value1 = var _1= CALCULATE(COUNT('Table'[value_1re]),FILTER(ALL('Table'),'Table'[Name]=SELECTEDVALUE('Table'[Name])&&'Table'[value_1re]<>BLANK()))
return 
IF(_1=BLANK(),_1+1,_1)
value2 = var _1= CALCULATE(COUNT('Table'[Index]),FILTER(ALL('Table'),'Table'[value_2re]=SELECTEDVALUE('Table'[value_2re])&&'Table'[Name]=SELECTEDVALUE('Table'[Name])&&'Table'[Success]="Y"))
return 
_1
Measure 2 = MAXX(FILTER(ALL('Table'),'Table'[Name]=SELECTEDVALUE('Table'[Name])),[value2])

vpollymsft_0-1666688395079.png

Best Regards

Community Support Team _ Polly

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Fantastic, thank you so much! You've made my day!

Greg_Deckler
Community Champion
Community Champion

@BigPatJennings You are looking for Cthulhu. And you will need an Index or something similar. Cthulhu - Microsoft Power BI Community



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

Helpful resources

Announcements
May Power BI Update Carousel

Power BI Monthly Update - May 2026

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

Fabric SQL PBI Data Days

Data Days 2026 coming soon!

Sign up to receive a private message when registration opens and key events begin.

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.