Situation
We have a baq that mimics the Priority Dispatch report that needs modified to show days sitting in the department. I have created a simple calculated field that calculates the difference between the last operation date to today. This method ignores our production availability/schedule by resource group.
Thought Process/Execution
Using information from the below post I have created the following expression:
case
when PriorOp.Calculated_PriorOp is null then (DATEDIFF(dd, max(OpenJobOpenOps4.JobHead_CreateDate), Constants.Today)) - ((DATEDIFF(wk, max(OpenJobOpenOps4.JobHead_CreateDate), Constants.Today) * 2) + (CASE WHEN DATEPART(dw, max(OpenJobOpenOps4.JobHead_CreateDate)) = 1 THEN 1 ELSE 0 END) + (CASE WHEN DATEPART(dw, Constants.Today) = 7 THEN 1 ELSE 0 END))
when PriorOp.Calculated_PriorOp is not null then (DATEDIFF(dd, max(LaborDtl1.ClockInDate), Constants.Today)) - ((DATEDIFF(wk, max(LaborDtl1.ClockInDate), Constants.Today) * 2) + (CASE WHEN DATEPART(dw, max(LaborDtl1.ClockInDate)) = 1 THEN 1 ELSE 0 END) + (CASE WHEN DATEPART(dw, Constants.Today) = 7 THEN 1 ELSE 0 END))
else '9999'
end
This seems to ignore all Saturdays and Sundays accurately. What I want to do next is create a statement that also ignores Fridays. I have tried adding similar statements to the cases that look at the date parts for 1 and 7. These do not operate as expected.
What I need
I need a way of modifying the above code to exclude Fridays from the calculation like it does for Saturdays and Sundays.
Next Steps
Once we figure out how to filter out individual days I would like to add the following and statement to make for a dynamic date filtering process for all of our companies:
(CASE WHEN DATEPART(dw, Constants.Today) = 7 AND ResourceGroup.DailyCapacity7 = 0 THEN 1 ELSE 0 END))
Building statements for every day of the week, 1-7, should allow for the Days Sitting calculation to filter based on our resource schedule and give a more accurate reading on how we are doing.
Thanks for the help!