fmcconaughy
New member
- Local time
- Today, 08:48
- Joined
- Jan 2, 2025
- Messages
- 8
Hello all, I have a problem trying to use an aggregate function to calculate values from a separate query. I have two separate queries, “Employees extended” and “DeliverablesPropNo”
“Employees” Relevant headers:
“Employee ID”, “Employee Name”
“Deliverables” relevant Headers:
“Job Name”, “Submitted By”, “Status”
Notes:
-Submitted by is displayed as a string but is a drop down of type Number referencing the employee ID in employees extended
- Status is also a drop down of type String
-There are about 50 employees, and about 700 rows in "DeliverablesPropNo”
In theory what I would like to do in a query is for each employee (each as a row) (called out as “Submitted By” in “Deliverables”) search through “deliverables” and create a count of all jobs of each status associated with that employee.
Ideally, the query values should be as follows, with a row for each employee:
“Employee Name”, “# of status 1 assigned to employee”, “# of Status 2 assigned to employee”….
When I try to do this in the query builder, I keep getting the error “Your Query does not include the specified Expression ‘ID’ as part of an Aggregate Function”. I am not quite sure what to do here as I am a bit inexperienced with SQL, and help would be appreciated. Thank you!
Count syntax:
Countstatus1: Sum(IIf([DeliverablesPropNo]![Submitted By]=[Employees Extended]![ID] And [DeliverablesPropNo]![Status]="Status 1",1,0))
My SQL Code is Below:
SELECT [Employees Extended].ID, [Employees Extended].[Employee Name], Sum(IIf([DeliverablesPropNo]![Submitted By]=[Employees Extended]![ID] And [DeliverablesPropNo]![Status]="Status 1",1,0)) AS countstatus1, Sum(IIf([DeliverablesPropNo]![Submitted By]=[Employees Extended]![ID] And [DeliverablesPropNo]![Status]="Status 2",1,0)) AS countstatus2, Sum(IIf([DeliverablesPropNo]![Submitted By]=[Employees Extended]![ID] And [DeliverablesPropNo]![Status]="Status 3",1,0)) AS countstatus3, Sum(IIf([DeliverablesPropNo]![Submitted By]=[Employees Extended]![ID] And [DeliverablesPropNo]![Status]="Status 4",1,0)) AS countstatus 4, Sum(IIf([DeliverablesPropNo]![Submitted By]=[Employees Extended]![ID] And [DeliverablesPropNo]![Status]="Status 5",1,0)) AS countstatus5, Sum(IIf([DeliverablesPropNo]![Submitted By]=[Employees Extended]![ID] And [DeliverablesPropNo]![Status]="Status 6",1,0)) AS countstatus 6, [countstatus1]+[countstatus2]+[countstauts3]+[countstatus4]+[countstatus5]+[countstatus6] AS tot
FROM DeliverablesPropNo, [Employees Extended];
Please let me know is anything is unclear or if you need more information! Thanks!
“Employees” Relevant headers:
“Employee ID”, “Employee Name”
“Deliverables” relevant Headers:
“Job Name”, “Submitted By”, “Status”
Notes:
-Submitted by is displayed as a string but is a drop down of type Number referencing the employee ID in employees extended
- Status is also a drop down of type String
-There are about 50 employees, and about 700 rows in "DeliverablesPropNo”
In theory what I would like to do in a query is for each employee (each as a row) (called out as “Submitted By” in “Deliverables”) search through “deliverables” and create a count of all jobs of each status associated with that employee.
Ideally, the query values should be as follows, with a row for each employee:
“Employee Name”, “# of status 1 assigned to employee”, “# of Status 2 assigned to employee”….
When I try to do this in the query builder, I keep getting the error “Your Query does not include the specified Expression ‘ID’ as part of an Aggregate Function”. I am not quite sure what to do here as I am a bit inexperienced with SQL, and help would be appreciated. Thank you!
Count syntax:
Countstatus1: Sum(IIf([DeliverablesPropNo]![Submitted By]=[Employees Extended]![ID] And [DeliverablesPropNo]![Status]="Status 1",1,0))
My SQL Code is Below:
SELECT [Employees Extended].ID, [Employees Extended].[Employee Name], Sum(IIf([DeliverablesPropNo]![Submitted By]=[Employees Extended]![ID] And [DeliverablesPropNo]![Status]="Status 1",1,0)) AS countstatus1, Sum(IIf([DeliverablesPropNo]![Submitted By]=[Employees Extended]![ID] And [DeliverablesPropNo]![Status]="Status 2",1,0)) AS countstatus2, Sum(IIf([DeliverablesPropNo]![Submitted By]=[Employees Extended]![ID] And [DeliverablesPropNo]![Status]="Status 3",1,0)) AS countstatus3, Sum(IIf([DeliverablesPropNo]![Submitted By]=[Employees Extended]![ID] And [DeliverablesPropNo]![Status]="Status 4",1,0)) AS countstatus 4, Sum(IIf([DeliverablesPropNo]![Submitted By]=[Employees Extended]![ID] And [DeliverablesPropNo]![Status]="Status 5",1,0)) AS countstatus5, Sum(IIf([DeliverablesPropNo]![Submitted By]=[Employees Extended]![ID] And [DeliverablesPropNo]![Status]="Status 6",1,0)) AS countstatus 6, [countstatus1]+[countstatus2]+[countstauts3]+[countstatus4]+[countstatus5]+[countstatus6] AS tot
FROM DeliverablesPropNo, [Employees Extended];
Please let me know is anything is unclear or if you need more information! Thanks!