I have a SQL-Sever query that returns the Capacity available to a person on any particular day.
The result is returned against each assignment the person has planned on that particular day.
My problem is that it returns the total capacity for that day on each line of the query’s result.
So when you show all the results for one day for one person, in a linked pivot table in excel (for example), you get the number of records multiplied by the base capacity.
I have written another query that counts the number of assignments per day per person.
I would like to divide the Capacity from the first query, by the number of records returned by the second query, but don’t know how to join the queries together.
This is the query that returns the list of assignments by day with capacity:
SELECT
MSP_EpmAssignmentByDay.TimeByDay,
MSP_EpmAssignment.ResourceUID,
MSP_EpmAssignmentByDay.AssignmentActualWork,
MSP_EpmResourceByDay_UserView.Capacity
FROM
MSP_EpmAssignment MSP_EpmAssignment,
MSP_EpmAssignmentByDay MSP_EpmAssignmentByDay,
MSP_EpmResourceByDay_UserView
MSP_EpmResourceByDay_UserView
WHERE
MSP_EpmAssignmentByDay.AssignmentUID = MSP_EpmAssignment.AssignmentUID
AND MSP_EpmResourceByDay_UserView.TimeByDay = MSP_EpmAssignmentByDay.TimeByDay
This is the query that returns the number of assignments per day per person:
SELECT
count(TimeByDay) as DayCount
FROM
MSP_EpmAssignmentByDay_UserView
LEFT JOIN MSP_EpmAssignment_UserView
ON MSP_EpmAssignmentByDay_UserView.AssignmentUID =
MSP_EpmAssignment_UserView.AssignmentUID
GROUP BY ResourceUID, TimeByDay
Any help would be greatly appreciated.
Thanks
Assuming the only fields you need are those included in the query, try:
Alternatively, try changing the summary operation on Capacity in the pivot table to be MAX instead of SUM.
EDIT: To include a count of records for the same ResourceUID and TimeByDay in the details, try: