Find consecutive dates in table

rileybloke

New Member
Joined
Feb 7, 2013
Messages
43
Hi,

I have a table of data that contains employee attendance records.

The table consists of employee name, date, attended mins, and absence mins

I need to find where an employee as been off sick for 15 consecutive days, and exclude the absence mins of these days from the total sum of absences.

Any help with the DAX would be greatly appreciated.
Thanks
Phil
 
I suggest you put some effort into you calendar table. Get everything date related in there you can, including info about the holidays. If you can end up with a notion in the Calendar table of "this day, I expect people to be at work..." that will help our problems :)

Imagine you have a column in your calendar table "ValidWorkday" that is a 1 if missing that day would require using a sick day. Then, we could invent a "WorkdayNumber" column like:

=IF (Calendar[ValidWorkday],
CALCULATE(COUNTROWS(Calendar), FILTER(Calendar, Calendar[Date] <= EARLIER(Calendar[Date]) && Calendar[ValidWorkday] = 1))
)

Then in the Attendance table you could do something like...
Code:
=CALCULATE(COUNTROWS(Attendance),
         FILTER(Calendar, Calendar[WorkDayNumber] > RELATED(Calendar[WorkDayNumber]) - 15  &&
                                            Calendar[WorkDayNumber] <= RELATED(Calendar[WorkDayNumber])),
         Attendance[Sick Day] = "Y",
         FILTER(Attendance,Attendance[Clock No]=EARLIER( Attendance[Clock No]))
    )
Which is the "Of the last 15 working days, how many did you miss?" If it's 15, then it's probably interesting.

(though, it is not super clear to me what we do if they missed 20 days in a row)
 
Upvote 0

Excel Facts

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.
I know you want to do this in DAX, but if you can use Power Query I suspect it would be much easier to find these ranges when you are loading the data. You could then create another column in your table that identified these ranges, making the DAX required simpler.

This problem is similar to the one I blogged about here: Aggregating By Local Groups In Power Query | Chris Webb's BI Blog. The last chapter of my Power Query book (Power Query Book Published! | Chris Webb's BI Blog) also has a similar worked example.

HTH,

Chris
 
Upvote 0
Okay, that blog post blew my mind, Chris! Power Query is kind of amazeballs sometimes.
 
Upvote 0
Hi Scott, thanks for the heads up on the calendar, I have taken your advice and now may calendar table is a little more useful. Your DAX to count the consecutive sick days is working thanks.
The rule is to exclude the sick attended for long term sick. Long term sick = any employee that is off sick for more than 15 consecutive days inclusive, therefore I'm now trying to sum the "Sick Attended" but exclude the "Sick Attended" where the count is between 1 and 15 and exceeds 15, failing miserably any ideas? thanks again.
I updated the workbook.

Thanks Chris, Ive never considered Powerview will have a dig around :)
 
Upvote 0
Juts been told that we should only be considering consecutive sick days when the sick day type = 1 or 3 !
Yikes! just to make it more complicated :(
 
Upvote 0
Model looks pretty good to me.

Does this give what you want? (ignoring that sick day type :))
=CALCULATE([Absence Hrs], Attendance[Consecutive Sick Count] < 15)
 
Upvote 0

Forum statistics

Threads
1,215,009
Messages
6,122,674
Members
449,091
Latest member
peppernaut

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top