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
Anonymous
Not applicable

Build measure or column to show a streak by consecutive dates a person meets a request

I have a table with Names and Dates. This table shows me that a person completed the request total for a given day. I'd like to create a measure to count the streak of days they meet requests.

 

For example: below shows two people - Berry and Bob.

Berry had a streak from 2019-12-10 to 2019-12-13 so I'd like to see the streak column count 1,2,3,4 and then because there is no record for Berry on 2019-12-14 the streak ends. A new streak would begin on the date that Berry has a record (in this case 2019-12-16).

BuildingAStreakExample.png

Here is the expected result that I just created in Excel - streak of days in a row:

 

StreakHelpExpectedResult.png

 

Any help on this would be really appreciated. This one has me stumped.

 

Thanks, Ben

1 ACCEPTED SOLUTION
v-frfei-msft
Community Support
Community Support

Hi @Anonymous ,

 

I have created a sample for your reference, please check the following steps as below.

1. Insert an index column in power query.

2. Then we can create the calculated columns to work on it.

Column = 
VAR ind = 'Table'[Index] - 1
VAR lastd =
    CALCULATE ( MAX ( 'Table'[Date] ), FILTER ( 'Table', 'Table'[Index] = ind ) )
VAR ld = 'Table'[Date] - 1
RETURN
    IF ( lastd = ld, 1, BLANK () )
Column 2 = 
var ind = 'Table'[Index]
var lastindex = CALCULATE(MAX('Table'[Index]),FILTER('Table','Table'[Column]=BLANK() && 'Table'[Index]<ind))
return
IF('Table'[Column]<>BLANK(),lastindex,'Table'[Index])

countrows = 
CALCULATE (
    COUNTROWS ( 'Table' ),
    FILTER (
        'Table',
        'Table'[Name] = EARLIER ( 'Table'[Name] )
            && 'Table'[Column 2] = EARLIER ( 'Table'[Column 2] )
            && 'Table'[Index] <= EARLIER ( 'Table'[Index] )
    )
)

Capture.PNG

 

Pbix as attached.

 

Community Support Team _ Frank
If this post helps, then please consider Accept it as the solution to help the others find it more quickly.

View solution in original post

3 REPLIES 3
andre
Memorable Member
Memorable Member

here is a video on how to calculate a streak without having to do anything wiht calculated columns.. all of the logic is in the measure itself:

v-frfei-msft
Community Support
Community Support

Hi @Anonymous ,

 

I have created a sample for your reference, please check the following steps as below.

1. Insert an index column in power query.

2. Then we can create the calculated columns to work on it.

Column = 
VAR ind = 'Table'[Index] - 1
VAR lastd =
    CALCULATE ( MAX ( 'Table'[Date] ), FILTER ( 'Table', 'Table'[Index] = ind ) )
VAR ld = 'Table'[Date] - 1
RETURN
    IF ( lastd = ld, 1, BLANK () )
Column 2 = 
var ind = 'Table'[Index]
var lastindex = CALCULATE(MAX('Table'[Index]),FILTER('Table','Table'[Column]=BLANK() && 'Table'[Index]<ind))
return
IF('Table'[Column]<>BLANK(),lastindex,'Table'[Index])

countrows = 
CALCULATE (
    COUNTROWS ( 'Table' ),
    FILTER (
        'Table',
        'Table'[Name] = EARLIER ( 'Table'[Name] )
            && 'Table'[Column 2] = EARLIER ( 'Table'[Column 2] )
            && 'Table'[Index] <= EARLIER ( 'Table'[Index] )
    )
)

Capture.PNG

 

Pbix as attached.

 

Community Support Team _ Frank
If this post helps, then please consider Accept it as the solution to help the others find it more quickly.
Greg_Deckler
Super User
Super User

You might be able to adapt Cthulhu for this purpose:

https://community.powerbi.com/t5/Quick-Measures-Gallery/Cthulhu/m-p/509739?search-action-id=98319201...


@ 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.