I have a Sales Table and a Discounts table.
The main dataset is a Sales table has sales per person.
Every person is associated under only one project and every project has only one supervisor.
The second dataset - discounts table has the discount entry for each Project
Sales Table
Supervisor | Company |Project |Person |Sale
Adam | CompanyA |CompA-01 |Amy |100
Adam | CompanyA |CompA-02 |Beth |200
Adam | CompanyA |CompA-02 |Cary |200
Jenny | CompanyA |CompA-05 |Dawn |300
Jenny | CompanyA |CompA-05 |Emma |400
Discounts table
Company | Project |Month |Amount
CompanyA| CompA-02 |Jan |500
CompanyA| CompA-02 |Feb |500
CompanyA| CompA-05 |Jan |1000
I want to display a report where the Discounts field is calculated as below
Supervisor | Company |Project |Person |Sales |Discounts
Adam
CompanyA 500 1000 <---HELP CALCULATE THIS
CompA-01 100 0
Amy 100
CompA-02 400 1000
Beth 200
Cary 200
...
...
TOTAL 12000 2000
I have following row groups in my report:
Supervisor Group
---Company Group
-----Project Group
----------Details
I am able to calculate the Discount column at the Project Grouping level as follows
=Code.SumLookup(LookupSet(Fields!Project.Value,Fields!Project.Value,Fields!amount.Value,"Discounts"))
Then at the Total Level I calculate the discount as:
=Sum(Fields!amount.Value, "Discounts")
I need help figuring out how to calculate the sum of the discounts at the Company and Supervisor level.
As many of you suggested that my query was the problem I just wanted to go ahead and demo exactly what issues I am facing.
As suggested I redesigned the query using a join
SELECT Sales.Supervisor, Sales.Company, Sales.Project, Sales.Person, Sales.SaleAmt, SUM(Discounts.Amount)
FROM Sales
LEFT OUTER JOIN Discounts
ON Sales.Company = Discounts.Company
AND Sales.Project = Discounts.Project
group by Sales.Supervisor, Sales.Company, Sales.Project, Sales.Person, Sales.SaleAmt, Discounts.Amount
created a report like
The report previews like this
Notice how the discount values are summed up all wrong. What can I do to correct this?