I am current trying to Dynamically Calculate Consecutive worked and absent days for a group of employees, however this as proven to be quite a difficult task. The RAW table looks something like this:
Date | ID | Absent |
---|---|---|
6/1/2021 | 1234 | 1 |
6/2/2021 | 1234 | 1 |
6/32021 | 1234 | 1 |
6/4/2021 | 1234 | 0 |
6/1/2021 | 6789 | 1 |
6/2/2021 | 6789 | 0 |
I would like to use Dax (not Power Query) to calculate the consecutive days they were absent, the closest I have come to a solution is the following, Shout out SQLBI:
DaysWith0 =
VAR CurrentDate = MAX('Calendar'[Date])
VAR FirstDateEver = CALCULATE(MIN( 'Calendar'[Date]), REMOVEFILTERS())
VAR PrevWorked =
CALCULATE(
MAX('RawDataTable'[Date]),'Calendar'[Date] <= CurrentDate)
VAR PrevDate = COALESCE(PrevWorked,FirstDateEver)
VAR Result = INT(CurrentDate - PrevDate)
RETURN
Result
But this only counts the consecutive days that have no data (no schedule). I need 2 measures that shows the consecutive worked days, and the consecutive absents.