Please verify the following statements. If there may be more than one active level for a project, then
Code:
Project.Assigned, (name or ID of sales rep)
Project.[Account Name], (name or ID of account) One Rep may have multiple accounts
Project.Project, (name or ID of Project) One account may have multiple projects
Project.Level, (name or ID of level) One project may have multiple levels
Project.Revenue, (amount of revenue) One level has only one revenue
Project.Active, (yes or no) One level is either active or inactive
If the above is correct, then use the following:
Code:
SELECT
P1.Assigned,
( SELECT Sum(P2.Revenue)
FROM Project AS P2
WHERE ((P2.Active=True)
AND (P2.Assigned = P1.Assigned))
) As TotActRev,
P1.[Account Name],
P1.Project,
P1.Level,
First(P1.Active) AS Active,
Sum(P1.Revenue) AS Revenue
FROM Project AS P1
WHERE (P1.Active = True)
GROUP BY
TotActRev,
P1.Assigned,
P1.[Account Name],
P1.Project,
P1.Level
ORDER BY
TotActRev DESC,
P1.Assigned,
P1.[Account Name],
P1.Project,
P1.Level
;
On the other hand, if there is only one active level for each project:
Code:
Project.Assigned, (name or ID of sales rep)
Project.[Account Name], (name or ID of account) One Rep may have multiple accounts
Project.Project, (name or ID of Project) One account may have multiple projects
Project.Level, (name or ID of level) One project has only one level
Project.Revenue, (amount of revenue) One project has only one revenue
Project.Active, (yes or no) One project is either active or inactive
If the above is correct, then use the following:
Code:
SELECT
P1.Assigned,
( SELECT Sum(P2.Revenue)
FROM Project AS P2
WHERE ((P2.Active=True)
AND (P2.Assigned = P1.Assigned))
) As TotActRev,
P1.[Account Name],
P1.Project,
First(P1.Level) AS Level,
First(P1.Active) AS Active,
Sum(P1.Revenue) AS Revenue
FROM Project AS P1
WHERE (P1.Active = True)
GROUP BY
TotActRev,
P1.Assigned,
P1.[Account Name],
P1.Project
ORDER BY
TotActRev DESC,
P1.Assigned,
P1.[Account Name],
P1.Project
;