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

Join us at FabCon Atlanta from March 16 - 20, 2026, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM. Register now.

Reply
Anonymous
Not applicable

count number of consecutive days

Hi, 

 

I would like to have the count of consecutive days in a calculated column based on for example sickday.

eks
employee   date           Sick =1     consecutive days
A               1.1.2020       1                2 (1.1+2.1)

B                1.1.2020      1                 3 (1.1+2.1+3.1)
C                1.1.2020      0                 0
A                2.1.2020       1                2 (1.1+2.1)
B                2.1.2020       1                 3 (1.1+2.1+3.1)

C                2.1.2020        1                2 (2.1+3.1)

A                3.1.2020        0                0

B                 3.1.2020       1                3 (1.1+2.1+3.1)
C                 3.1. 2020      1                 2 (2.1+3.1)

Any help would be grateful!

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

hi  @Anonymous 

You could use this formula to get it:

Result = 
VAR _date1 =
    CALCULATE (
        MAX ( 'Table'[date] ),
        FILTER (
            CALCULATETABLE ( 'Table',ALLEXCEPT('Table','Table'[employee] ),'Table'[Sick]=0),
            'Table'[date] <= EARLIER (  'Table'[date] )
        )
    )
VAR _date2 =
    CALCULATE (
        MIN(  'Table'[date] ),
        FILTER (
            CALCULATETABLE ( 'Table',ALLEXCEPT('Table','Table'[employee] ),'Table'[Sick]=0),
            'Table'[date] > EARLIER (  'Table'[date] )
        )
    )
VAR _date3=IF( ISBLANK(_date2),CALCULATE (
        MAX ( 'Table'[date] ),ALLEXCEPT('Table','Table'[employee] ))+1,_date2)

RETURN
var a=    CALCULATE (
        COUNTROWS ( 'Table' ),
        FILTER (
           ALLEXCEPT( 'Table','Table'[employee]),
             'Table'[date] <_date3&& 
                'Table'[date] > _date1
        )
    ) + 0

return
 if('Table'[Sick]=0,0,a)

 

Regards,

Lin

Community Support Team _ Lin
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

6 REPLIES 6
v-lili6-msft
Community Support
Community Support

hi  @Anonymous 

You could use this formula to get it:

Result = 
VAR _date1 =
    CALCULATE (
        MAX ( 'Table'[date] ),
        FILTER (
            CALCULATETABLE ( 'Table',ALLEXCEPT('Table','Table'[employee] ),'Table'[Sick]=0),
            'Table'[date] <= EARLIER (  'Table'[date] )
        )
    )
VAR _date2 =
    CALCULATE (
        MIN(  'Table'[date] ),
        FILTER (
            CALCULATETABLE ( 'Table',ALLEXCEPT('Table','Table'[employee] ),'Table'[Sick]=0),
            'Table'[date] > EARLIER (  'Table'[date] )
        )
    )
VAR _date3=IF( ISBLANK(_date2),CALCULATE (
        MAX ( 'Table'[date] ),ALLEXCEPT('Table','Table'[employee] ))+1,_date2)

RETURN
var a=    CALCULATE (
        COUNTROWS ( 'Table' ),
        FILTER (
           ALLEXCEPT( 'Table','Table'[employee]),
             'Table'[date] <_date3&& 
                'Table'[date] > _date1
        )
    ) + 0

return
 if('Table'[Sick]=0,0,a)

 

Regards,

Lin

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

This solved my problem! Thank you!


Did my answer(s) help you? Give it a kudos by clicking the Thumbs Up!
Did my post answer your question(s)? Mark my post as a solution. This will help others find the solution.

Proud to be a Super User!

Anonymous
Not applicable

Brilliant!!!!!

ryan_mayu
Super User
Super User

@Anonymous 

you can try to create a column

Column = if('Table'[Sick]=0,0,sumx(FILTER('Table','Table'[employee]=EARLIER('Table'[employee])),'Table'[Sick]))

1.PNG





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




Anonymous
Not applicable

Tnx for your reply, however it does not give the correct numbers.

amitchandak
Super User
Super User

@Anonymous , refer if these can help

https://community.powerbi.com/t5/Desktop/Build-measure-or-column-to-show-a-streak-by-consecutive-dates-a/td-p/899915

https://community.powerbi.com/t5/Desktop/Win-Losing-Streak/td-p/273547

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

Check out the October 2025 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.