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

Power BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. Register now.

Reply
babyjb1979
Helper I
Helper I

Calculation for consecutive work days for employee

Hello everyone,

 

I've been tasked with creating a report that tracks consecutive workdays. Within the employee transaction table, there are two key columns: [Employee ID] and [Work Date]. I've already added a new column that's working well, except it's not applied correctly when employees are grouped together.

babyjb1979_0-1694020906279.png

In an attempt to refine the report further, I introduced another column. Unfortunately, this didn't yield the desired results.

babyjb1979_1-1694021008398.png

I have submitted this question 3 times on the forum but haven't got any answer.  Your help would be greatly appreciated!

 

1 ACCEPTED SOLUTION

Hi, @babyjb1979 

 

You can try the following methods.

Column:

Judge = 
DATEDIFF ( [Work Date] - 2,
    MAXX ( FILTER ( 'Table',[Employee ID]=EARLIER('Table'[Employee ID])&& [Work Date]= EARLIER ( 'Table'[Work Date] ) - 1 ), [Work Date] ),
    DAY
)
First day = IF([Judge]<>BLANK(),0,1)
Consecutive days = 
VAR last_1_date =
    CALCULATE ( MAX ( 'Table'[Work Date]),
        FILTER ( 'Table',
            [Work Date] <= EARLIER ( 'Table'[Work Date] )
            &&[Employee ID]=EARLIER('Table'[Employee ID])
            && [First day] = 1
        )
    )
VAR sum_ =
    CALCULATE ( COUNTROWS ( 'Table' ),
        FILTER ( 'Table',
            [Work Date] >= last_1_date
            &&[Employee ID]=EARLIER('Table'[Employee ID])
            &&[Work Date] <= EARLIER ( 'Table'[Work Date] )
        )
    )
RETURN
    IF ( [First day] = 1, 1, sum_ )

vzhangti_0-1694137910499.png

Is this the result you expect?

 

Best Regards,

Community Support Team _Charlotte

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

3 REPLIES 3
ThxAlot
Super User
Super User

Calculation for consecutive.pbix

 

With only one helper column,

ThxAlot_0-1694217575207.png



Expertise = List.Accumulate(


        {Days as from Today},


        {Skills and Knowledge},


        (Current, Everyday) => Current & Day.LearnAndPractise(Everyday)


)



babyjb1979
Helper I
Helper I

Work DateEmployee ID
3/11/20231
3/25/20231
3/27/20231
3/28/20231
3/29/20231
3/30/20231
3/31/20231
4/8/20231
4/22/20231
5/6/20231
5/20/20231
6/3/20231
6/17/20231
7/1/20231
7/15/20231
7/29/20231
8/12/20231
8/30/20231
8/31/20231
9/1/20231
9/5/20231
9/6/20232
9/7/20232
9/8/20232
9/9/20232
9/10/20232
9/11/20232
9/12/20232

Hi, @babyjb1979 

 

You can try the following methods.

Column:

Judge = 
DATEDIFF ( [Work Date] - 2,
    MAXX ( FILTER ( 'Table',[Employee ID]=EARLIER('Table'[Employee ID])&& [Work Date]= EARLIER ( 'Table'[Work Date] ) - 1 ), [Work Date] ),
    DAY
)
First day = IF([Judge]<>BLANK(),0,1)
Consecutive days = 
VAR last_1_date =
    CALCULATE ( MAX ( 'Table'[Work Date]),
        FILTER ( 'Table',
            [Work Date] <= EARLIER ( 'Table'[Work Date] )
            &&[Employee ID]=EARLIER('Table'[Employee ID])
            && [First day] = 1
        )
    )
VAR sum_ =
    CALCULATE ( COUNTROWS ( 'Table' ),
        FILTER ( 'Table',
            [Work Date] >= last_1_date
            &&[Employee ID]=EARLIER('Table'[Employee ID])
            &&[Work Date] <= EARLIER ( 'Table'[Work Date] )
        )
    )
RETURN
    IF ( [First day] = 1, 1, sum_ )

vzhangti_0-1694137910499.png

Is this the result you expect?

 

Best Regards,

Community Support Team _Charlotte

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

Helpful resources

Announcements
June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

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

June 2025 community update carousel

Fabric Community Update - June 2025

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