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
klaustukas
Frequent Visitor

Spotting Sequences

Hello,

 

I have the following problem.

 

 Suppose I am interested in finding sequences in [Value] made of 1's. I want to write the starting index of a sequence next to each of its members (column [Starting_Index]). Here is an illustration (I have columns [Index] and [Value], and want to produce column [Starting Index]):

 

IndexValueStarting_Index
100
212
312
412
500
600
717
817

 

 

I thought maybe I could use the Starting_Index column in its creation itself, but obviously that is not how it works.

 

Starting_Index = IF([Value]=0;0;IF(LOOKUPVALUE([Value];[Index];[Index]-1)<>[Value];[Index];LOOKUPVALUE([Starting_Index];[Index];[Index]-1)))

 

I would be very grateful if somebody could help me.

 

Thank you.

1 ACCEPTED SOLUTION
jthomson
Solution Sage
Solution Sage

The approach I'd take would be to find the last smaller index value that's zero, then add one to it - try:

 

startingindex = var currentindex = max(Table1[index]) var currentvalue = max(Table1[value]) var lastzero = CALCULATE(max(Table1[index]),Table1[value]=0,Table1[index]<currentindex) return if(currentvalue=0,blank(),lastzero+1)

 

startingindex.PNG

View solution in original post

1 REPLY 1
jthomson
Solution Sage
Solution Sage

The approach I'd take would be to find the last smaller index value that's zero, then add one to it - try:

 

startingindex = var currentindex = max(Table1[index]) var currentvalue = max(Table1[value]) var lastzero = CALCULATE(max(Table1[index]),Table1[value]=0,Table1[index]<currentindex) return if(currentvalue=0,blank(),lastzero+1)

 

startingindex.PNG

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.