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

Learn from the best! Meet the four finalists headed to the FINALS of the Power BI Dataviz World Championships! Register now

Reply
Jamesfindog
Helper I
Helper I

Displaying (Flagging) employees which have attended on a certain number of consecutive days

Hi All,

 

Looking to flag when an employee has worked at least 3 consecutive days.

 

Data example:

EmployeeDay
A1
A2
A3
A4
A5
A6
B1
B2
C1
A7
A8
A9
B10
B11
B12
A12
A13
A14

 

So, employee A should be flagged 3 times, and B once, with C never.

 

I'd want to be able to display which employees have worked 3 or more consecutive days, potentially with the days they have worked. (Day is actually a date field, I simplified it to numbers for this help message).

 

What do you think is the best way to display this?

 

Cheers!

1 ACCEPTED SOLUTION
AmiraBedh
Super User
Super User

Hello !

Thank you for posting Microsoft Fabric community.

 

You can take the employee distinct dates in the current filters and rank them and compute GrpKey =o each consecutive run shares a key then group by that key to get each run length. Pick the longest run length and do QUOTIENT(longest, 3).

 

 

Flag (longest run / 3) =
VAR Emp =
    SELECTEDVALUE ( 'Attendance'[Employee] )
VAR DatesForEmp =
    CALCULATETABLE ( DISTINCT ( 'Attendance'[Day] ), 'Attendance'[Employee] = Emp )
VAR Ranked =
    ADDCOLUMNS (
        DatesForEmp,
        "DaySerial", INT ( 'Attendance'[Day] ),
        "Idx", RANKX ( DatesForEmp, 'Attendance'[Day], , ASC, DENSE )
    )
VAR WithGrp =
    ADDCOLUMNS ( Ranked, "GrpKey", [DaySerial] - [Idx] )
VAR Runs =
    GROUPBY ( WithGrp, [GrpKey], "Len", COUNTX ( CURRENTGROUP (), 1 ) )
VAR LongestLen =
    MAXX ( Runs, [Len] )
RETURN
    QUOTIENT ( LongestLen, 3 )

 

AmiraBedh_0-1757513763195.png

 

 

 


Proud to be a Power BI Super User !

Microsoft Community : https://docs.microsoft.com/en-us/users/AmiraBedhiafi
Linkedin : https://www.linkedin.com/in/amira-bedhiafi/
StackOverflow : https://stackoverflow.com/users/9517769/amira-bedhiafi
C-Sharp Corner : https://www.c-sharpcorner.com/members/amira-bedhiafi
Power BI Community :https://community.powerbi.com/t5/user/viewprofilepage/user-id/332696

View solution in original post

8 REPLIES 8
v-echaithra
Community Support
Community Support

Hi @Jamesfindog ,

May I ask if you have resolved this issue? Please let us know if you have any further issues, we are happy to help.

Thank you.

v-echaithra
Community Support
Community Support

Hi @Jamesfindog ,

We’d like to follow up regarding the recent concern. Kindly confirm whether the issue has been resolved, or if further assistance is still required. We are available to support you and are committed to helping you reach a resolution.

Best Regards,
Chaithra E.

v-echaithra
Community Support
Community Support

Hi @Jamesfindog ,

Thank you @johnt75 , @AmiraBedh , @srlabhe  for your inputs.

I hope the information provided is helpful. I wanted to check whether you were able to resolve the issue with the provided solutions. Please let us know if you need any further assistance.

Thank you.

johnt75
Super User
Super User

There's a flaw in your test data. As A's attendance from 6 continues at 7 there are only 2 stretches where they attend consecutively for more than 3 days.

You can create a measure like

VAR AllDate = ALL('Date'[Date])
VAR DatesAttended = VALUES('Table'[Date])
VAR DatesNotAttended = EXCEPT(
    AllDate,
    DatesAttended
)
VAR TableForGrouping = GENERATE(
    DatesAttended,
    VAR RefDate = 'Table'[Date]
    VAR PrevNotAttended = MAXX(
        FILTER(
            DatesNotAttended,
            'Date'[Date] <= RefDate
        ),
        'Date'[Date]
    )
    VAR NumDays = DATEDIFF(
        PrevNotAttended,
        RefDate,
        DAY
    )
    VAR Result = ROW(
        "@num days", NumDays,
        "@prev not attended", PrevNotAttended
    )
    RETURN
        Result
)
VAR AttendedStretches = GROUPBY(
    TableForGrouping,
    [@prev not attended],
    "@longest attendance",
    MAXX(
        CURRENTGROUP(),
        [@num days]
    )
)
VAR Result = COUNTROWS(FILTER(
    AttendedStretches,
    [@longest attendance] >= 3
))
RETURN
    Result

This works out how for each date how many days continuous attendance has happened, as well as storing the previous date on which the person did not attend. It then groups all the dates with the same non-attendance date and gets the max of the attendance. It finally counts how many groups have 3 or more consecutive attendance dates.

See attached PBIX for reference.

AmiraBedh
Super User
Super User

Hello !

Thank you for posting Microsoft Fabric community.

 

You can take the employee distinct dates in the current filters and rank them and compute GrpKey =o each consecutive run shares a key then group by that key to get each run length. Pick the longest run length and do QUOTIENT(longest, 3).

 

 

Flag (longest run / 3) =
VAR Emp =
    SELECTEDVALUE ( 'Attendance'[Employee] )
VAR DatesForEmp =
    CALCULATETABLE ( DISTINCT ( 'Attendance'[Day] ), 'Attendance'[Employee] = Emp )
VAR Ranked =
    ADDCOLUMNS (
        DatesForEmp,
        "DaySerial", INT ( 'Attendance'[Day] ),
        "Idx", RANKX ( DatesForEmp, 'Attendance'[Day], , ASC, DENSE )
    )
VAR WithGrp =
    ADDCOLUMNS ( Ranked, "GrpKey", [DaySerial] - [Idx] )
VAR Runs =
    GROUPBY ( WithGrp, [GrpKey], "Len", COUNTX ( CURRENTGROUP (), 1 ) )
VAR LongestLen =
    MAXX ( Runs, [Len] )
RETURN
    QUOTIENT ( LongestLen, 3 )

 

AmiraBedh_0-1757513763195.png

 

 

 


Proud to be a Power BI Super User !

Microsoft Community : https://docs.microsoft.com/en-us/users/AmiraBedhiafi
Linkedin : https://www.linkedin.com/in/amira-bedhiafi/
StackOverflow : https://stackoverflow.com/users/9517769/amira-bedhiafi
C-Sharp Corner : https://www.c-sharpcorner.com/members/amira-bedhiafi
Power BI Community :https://community.powerbi.com/t5/user/viewprofilepage/user-id/332696
srlabhe
Super User
Super User

Do you mean even Employee A worked through Day 1 - Day 6 it should be flagged only once or twice as he worked six days which are twice of 3 consecutive days ?

Hi mate, once.


As this is a single consecutive period, just happens to be over 3 days.

 

Hope this makes sense.

Create a column as below 

then take differnce beween this and your date column.

Then filter the difference for 1.

then take sum(difference) , here it should sum only consecutive days and where thsoe are 3 you can flag accordingly

 

Previous Row Value =
CALCULATE(
MAX( 'Values'[Value] ), // Replace 'Values'[Value] with your column
TOPN(
1,
FILTER(
ALLSELECTED( 'Values' ), // Replace 'Values' with your table
'Values'[Value Date] < MAX( 'Values'[Value Date] ) // Replace 'Values'[Value Date] with your date column
),
'Values'[Value Date], // Replace 'Values'[Value Date] with your date column
DESC
)
)

 

Noe for cases like employee A you have to tweak the logic saying if its >3 then count it once.

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.

February Power BI Update Carousel

Power BI Monthly Update - February 2026

Check out the February 2026 Power BI update to learn about new features.