Reputation: 13
As the title says, I'm looking for a way to calculate the percentage of completed tasks a person has. Data is structured so that each individual has can have many tasks, and each task can have many sub-tasks, as described below:
Employees
Tasks
Sub-Tasks
I've been trying to make a report (named "Task Completion Rates") that lists all employees, the number of completed tasks they have, the total number of tasks they have, and their completion rate as a percentage. At the moment, I have the following two queries:
Are both of those necessary, or is there a way to get both counts from one query? Also, how would I go about using those totals in the report? The report's Record Source is set to the Employees table so that it can list them all. I've got text boxes ready to go for each total, but I'm having problems using the expression builder in the source for each text box to actually display the results of the queries. I set the source for one of the text boxes to =[qry_TotalTasksPerEmployee]![TotalTasks] (via expression builder) but it keeps prompting me to enter a value for [qry_TotalTasksPerEmployee]. Any ideas on how get this working?
Upvotes: 1
Views: 3504
Reputation: 702
Try taking the mean of your completed value. For example:
SELECT employee_id, -avg(Completed) FROM [Tasks] GROUP BY employee_id
The -
before avg
is because true
is stored as -1
, as pointed out by @Neil.
I'm not sure what you mean about the report - it should be easy to place query results in a report.
Upvotes: 1
Reputation: 5360
I'm not really into msaccess reports but since completed seems to be either a 0 or a 1 you should work towards the following query -Edit turns out it's either 1 or -1 for bools so can't do a sum(completed) but need an IIF()
Select employee_id, count(*), sum(IIF(completed,1,0)), sum(IIF(completed,1,0))*100/count(*) as rate
From employees
Left join tasks
On tasks.employee_id = employees.employee_id
Group by employee_id
Note that this does create a division by zero problem for employees without tasks. You will have to deceide how to deal withbthose (exclude, show as 0% or ...)
Upvotes: 0