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

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.

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

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
v-rongtiep-msft
Community Support
Community Support

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 @v-rongtiep-msft ,

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

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
Super User
Super User

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


@ 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!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.