Forum Discussion

bice_cold's avatar
bice_cold
Frequent Visitor
7 years ago

Consecutive Days for Employees

I have a table named [Attendance] that looks like this:

 

INDEXADP ID#DateType
1A1/1/2019sick
2B1/1/2019vacation
3A1/2/2019sick
4A1/3/2019sick
5B1/5/2019vacation
6A2/7/2019vacation
7A2/20/2019sick
8A2/21/2019vacation

 

I also have a relationship set up to a date table.

 

I need to get the value of consecutive days for each time the employee is out sick. A measure would be great, but if a calculated column works I would happily accept that as a solution. My expected output in a table would look like this:

 

INDEXADP ID#DateTypeconsecutive
1A1/1/2019sick1
2B1/1/2019vacation0
3A1/2/2019sick2
4A1/3/2019sick3
5B1/5/2019vacation0
6A2/7/2019vacation0
7A2/20/2019sick1
8A2/21/2019vacation0


Right now, I have a column that gives me a value if the day is consecutive sick day or not, but I'm not sure how to aggregate it for the desired output. It looks like this:

INDEXADP ID#DateTypeconsecutive
1A1/1/2019sick1
2B1/1/2019vacation0
3A1/2/2019sick1
4A1/3/2019sick

1

 

Here's what I have so far -

 

Is Consecutive = 

// This column determines if the occurrence is consecutive

var adpid = AttendanceLog[ADP ID#]
var rowDate = AttendanceLog[Date]

var previousWorkday =
CALCULATE(
    MAX('Date'[Date]),
        FILTER('Date',
            'Date'[Date] < rowDate
            && 'Date'[IsWorkDay] = 1
        )
)

// determine if the last workday was an occurrence or not
// if the previous day has a value for unexcused absence and is not scheduled, it will return the index
var lastOccurrenceCheck =
MAXX(
    FILTER(AttendanceLog,
        AttendanceLog[ADP ID#] = adpid
        && AttendanceLog[Date] = previousWorkday
        && AttendanceLog[Absence Code] <> "scheduled"
    ),
    AttendanceLog[Index]
)

// if the row occurrence is a consecutive sick or unscheduled day, give it a value of 1. Otherwise, don't give it a value.
var isConsecutive =
IF(
    ISBLANK(lastOccurrenceCheck),
    0,
    1
)


return

isConsecutive

Thanks in advance for any help I can get!

1 Reply