B
Brian
Hi Everyone,
I've created a report based on a query
Tables
MonthlyFigures-- ID, Date(mm/yyyy), Figures, Manufacturer, Store
Stores -- ID, Name, Post Code
Manufacturer -- ID Name
Manufacturer ID and Store ID are Related to MonthlyFigures Manufacturer
and store
So, I have a sales report that displays the Store Name and Postcode and a
subreport in its detail section, the subreport is called Monthly and is
based on a query called Report that has all the figures and details
required for the report (Which is linked by Store ID).
Report Query --
SELECT Monthlys.Date,
LastYears.Date,
Monthlys.Manufacturer,
Monthlys.Store,
Monthlys.Figures,
LastYears.Figures,
MonthlyFigures.Figures,
(
Select Sum(MonthlyFigures.Figures)
FROM MonthlyFigures
WHERE Monthlys.Manufacturer = MonthlyFigures.Manufacturer AND
MonthlyFigures.Store = Monthlys.Store AND
MonthlyFigures.Date Between Monthlys.Date AND LastYears.Date;
) AS YTD
FROM LastYears, Monthlys INNER JOIN MonthlyFigures ON Monthlys.ID =
MonthlyFigures.ID
WHERE (
((Monthlys.Date)=GetReportDate()) AND
((Monthlys.Manufacturer)=[LastYears].[Manufacturer]) AND
((Monthlys.Store)=[LastYears].[Store])
);
This query makes a table with all the values I need, the problem comes
when I create the Report from this, it states that Multi-level group by
clause are not allowed in a subquery.
I searched the net and found that maybe I should use a Dsum() instead
of the subquery, this is my attempt
SELECT Monthlys.Date AS rDate,
Monthlys.Manufacturer AS rManufacturer,
Monthlys.Store AS rStore,
Monthlys.Figures AS rFigures,
LastYears.Figures AS rLastFigures,
DSum(MonthlyFigures.Figures, "MonthlyFigures",
([MonthlyFigures].[Date]
Between [Monthlys].[Date] AND [LastYears].[Date]) AND
([MonthlyFigures].[Manufacturer] = [Monthlys].[Manufacturer]) AND
([MonthlyFigures].[Store] = [Monthlys].[Store])
) AS YTD
FROM LastYears, Monthlys INNER JOIN MonthlyFigures ON Monthlys.ID =
MonthlyFigures.ID
WHERE (
((Monthlys.Date)=GetReportDate()) AND
((Monthlys.Manufacturer)=[LastYears].[Manufacturer]) AND
((Monthlys.Store)=[LastYears].[Store])
);
The YTD figures are way off (not even to total of everything that I was
getting)
This post if getting a little too long, so please let me know if I left
anything out.
I've created a report based on a query
Tables
MonthlyFigures-- ID, Date(mm/yyyy), Figures, Manufacturer, Store
Stores -- ID, Name, Post Code
Manufacturer -- ID Name
Manufacturer ID and Store ID are Related to MonthlyFigures Manufacturer
and store
So, I have a sales report that displays the Store Name and Postcode and a
subreport in its detail section, the subreport is called Monthly and is
based on a query called Report that has all the figures and details
required for the report (Which is linked by Store ID).
Report Query --
SELECT Monthlys.Date,
LastYears.Date,
Monthlys.Manufacturer,
Monthlys.Store,
Monthlys.Figures,
LastYears.Figures,
MonthlyFigures.Figures,
(
Select Sum(MonthlyFigures.Figures)
FROM MonthlyFigures
WHERE Monthlys.Manufacturer = MonthlyFigures.Manufacturer AND
MonthlyFigures.Store = Monthlys.Store AND
MonthlyFigures.Date Between Monthlys.Date AND LastYears.Date;
) AS YTD
FROM LastYears, Monthlys INNER JOIN MonthlyFigures ON Monthlys.ID =
MonthlyFigures.ID
WHERE (
((Monthlys.Date)=GetReportDate()) AND
((Monthlys.Manufacturer)=[LastYears].[Manufacturer]) AND
((Monthlys.Store)=[LastYears].[Store])
);
This query makes a table with all the values I need, the problem comes
when I create the Report from this, it states that Multi-level group by
clause are not allowed in a subquery.
I searched the net and found that maybe I should use a Dsum() instead
of the subquery, this is my attempt
SELECT Monthlys.Date AS rDate,
Monthlys.Manufacturer AS rManufacturer,
Monthlys.Store AS rStore,
Monthlys.Figures AS rFigures,
LastYears.Figures AS rLastFigures,
DSum(MonthlyFigures.Figures, "MonthlyFigures",
([MonthlyFigures].[Date]
Between [Monthlys].[Date] AND [LastYears].[Date]) AND
([MonthlyFigures].[Manufacturer] = [Monthlys].[Manufacturer]) AND
([MonthlyFigures].[Store] = [Monthlys].[Store])
) AS YTD
FROM LastYears, Monthlys INNER JOIN MonthlyFigures ON Monthlys.ID =
MonthlyFigures.ID
WHERE (
((Monthlys.Date)=GetReportDate()) AND
((Monthlys.Manufacturer)=[LastYears].[Manufacturer]) AND
((Monthlys.Store)=[LastYears].[Store])
);
The YTD figures are way off (not even to total of everything that I was
getting)
This post if getting a little too long, so please let me know if I left
anything out.