Hi all,
I've been trying to get a semi-complex measure out for over a day now but seem to be going round in circles. Most frustrating is I don't quite understand why one version throws an error, another throws out the wrong number and then whatever you guys come
up with will give me the correct answer!
I have a workbook uploaded here which I used for a different question, but majority of the data model is the same :
https://onedrive.live.com/?cid=1C0322C61F94C9E9&id=1C0322C61F94C9E9%21125
What I'm trying to do is find staff members that are at risk of burn out (eg consistently working > 8hrs a day)
My main timesheet table (Time) is as such:
StaffID (fk to staff table)
ClientID (fk to client table)
TaskID (fk to task table)
TimesheetDate (fk to date table)
EffortInHrs
my date dim is standard fare, only thing i've added is an EndOfWeekDate (eg EOWDate. sunday is the last day therefore for each date for this week the endofweekdate column = 18-jan. For last week it was 11-Jan etc) and I also have a 'last freshed date' that
shows the last time the model was refreshed
A staff member can only record time against a specific task once per day, but they can have multiple tasks across multiple clients for one day
The business rule im working with is
if they've worked more than 8hrs at least once in the last 3 weeks (dates that fall between EOWdate for 'now' minus 3 weeks and EOWdate for 'now' ), then return the sum of EffortInHrs for all clients for every day in the last 3 weeks
I've given up in getting it in one go so i'm trying to cobble together a number of calc columns and measures to get me closer.. but it all seems to stall
eg the following calc column (DailySumOfHrs)
=
CALCULATE (
SUM ( [EffortInHours] ),
FILTER (
ALLEXCEPT ( TIME, 'Time'[TimesheetDate], TIME[StaffID] ),
DATESBETWEEN (
'Date'[Date],
'time'[TimesheetDate],
'Time'[TimesheetDate]
)
)
)
gives me the sum of effort in hrs for the day for each staff member. I couldn't get a measure version of this working. It would either aggregate across all days/staff or give context errors.
So when I tried to take it to the next step to find the max using the same formula
=
CALCULATE (
SUM ( [EffortInHours] ),
FILTER (
ALLEXCEPT ( TIME, 'Time'[TimesheetDate], TIME[StaffID] ),
DATESBETWEEN (
'Date'[Date],
'time'[TimesheetDate],
'Time'[TimesheetDate]
)
)
)
I get errors, i'm guessing because i'm mixing my fact and date tables now and it doesn't know it can use the TimeSheetDate 'context' to filter.
To get the 'last 3 weeks' filter working I added the following to the date dim
=if([EndOfWeek]<[RefreshDateLocal] +7 && [EndOfWeek] > [RefreshDateLocal] -14,1,0)
i then used it in an intermediate measure to get the max at the weekly grain
WeeklyMax :=
IF (
MAX ( 'Date'[Last3WeeksFilter] ) = 1,
CALCULATE (
MAX ( TIME[DailySumOfHrs] ),
FILTER (
ALL ( 'Date'[date] ),
MAX ( 'Date'[EndOfWeek] ) = MAX ( 'Date'[EndOfWeek] )
),
'Date'[Last3WeeksFilter] = 1
),
BLANK ()
)
and finally the measure itself
BurntOutHrs:=if([WeeklyMax]>8,SUM([EffortInHours]),blank())
I am not happy with this at all. There are so many conditions (eg filters added) that need to be satisfied for this to return a sensible result and I need to expose a number of the 'backend' filters that users would need to add to the report to get the correct
answer.
As is, it only works for a simple Staff, date, burntouthrs report. If users attempt to create their own pivot table/chart and try to break it down by client or task it doesn't look right at all. I'd also like to be able to count how much stuff are working
long hrs but this approach wouldn't support that at all.
I could probably post dozens of my attempted dax that to me logically look like it should work but either aggregate wrong or throw context errors. Unfortunately my current approach to dax still is to try various, almost random variations until one works
for whatever reason
I always aim to have a measure that 'just works' in all contexts where it makes logical sense. For me to get that happening here i'd probably need to spend another few hrs trying all kinds of allexcept() conditions for each filter where i want it to work
and hope none contradict each other
Thinking about it now, this isn't really a separate measure at all.. i think a better approach would be to add a calc column to the staff table that checks if that staff member has >8hrs assigned for any day (i dont think the default time->staff relationship
would allow this though). But i'm still interested on how to accomplish it using the separate 'measure' approach
I'll go spend the rest of today trying to get the flag working in the staff dim!
Thanks!
Jakub @ Adelaide, Australia Blog