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

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.

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.