G
Guest
A table lists all the shipments by item, by order line, by date from the
year 2003 thru the present. One of the fields is a week number, YrWk, where
200420 denotes the 20th week of the year 2004.
The first query is a filtering query which limits the data to a specific
team code and time frame. In this instance the team is AD1 and the time
frame is >#12/13/2003#.
Next is a crosstab query based on the above query. This lists the data by
item number and sum of YrWl
The next query is based on the crosstab query above. This displays the item
number, the total for the timeframe, and the latest 15 weeks of shipments.
I would like to add a calculated filed in this query which will give the
AVERAGE weekly shipments of the last 15 weeks of shipments. Into a blank
filed I enter the following:
Ship15: Avg([200450]+[200449]+[200448]) and so on .
When I run the query I get the following message:
“You tried to execute a query that doesn’t include the specified expression
‘MtlNmbr’ as part of the aggregate function.â€
Is it possible to do what I want, or are there other steps which must be
taken?
The SQLs follow:
Query 1
SELECT tblShpngLines.MtlNmbr, tblShpngLines.PostingDate,
tblShpngLines.Descrip, tblShpngLines.Qty, tblItemData.MRPCntr,
tblShpngLines.YrWk
FROM tblShpngLines INNER JOIN tblItemData ON tblShpngLines.MtlNmbr =
tblItemData.MaterialNbr
WHERE (((tblShpngLines.PostingDate)>#12/13/2003#) AND
((tblItemData.MRPCntr)="AD1"))
ORDER BY tblShpngLines.YrWk DESC;
Crosstab query
TRANSFORM Sum(qryShpAndTeamAD1Only.Qty) AS [The Value]
SELECT qryShpAndTeamAD1Only.MtlNmbr, Sum(qryShpAndTeamAD1Only.Qty) AS [Total
Of Qty]
FROM qryShpAndTeamAD1Only
GROUP BY qryShpAndTeamAD1Only.MtlNmbr
ORDER BY qryShpAndTeamAD1Only.YrWk DESC
PIVOT qryShpAndTeamAD1Only.YrWk;
Last query
SELECT qryShpAndTeamAD1Only_Crosstab.MtlNmbr,
qryShpAndTeamAD1Only_Crosstab.[Total Of Qty],
qryShpAndTeamAD1Only_Crosstab.[200450],
qryShpAndTeamAD1Only_Crosstab.[200449],
qryShpAndTeamAD1Only_Crosstab.[200448],
qryShpAndTeamAD1Only_Crosstab.[200447],
qryShpAndTeamAD1Only_Crosstab.[200446],
qryShpAndTeamAD1Only_Crosstab.[200445],
qryShpAndTeamAD1Only_Crosstab.[200444],
qryShpAndTeamAD1Only_Crosstab.[200443],
qryShpAndTeamAD1Only_Crosstab.[200442],
qryShpAndTeamAD1Only_Crosstab.[200441],
qryShpAndTeamAD1Only_Crosstab.[200440],
qryShpAndTeamAD1Only_Crosstab.[200439],
qryShpAndTeamAD1Only_Crosstab.[200438],
qryShpAndTeamAD1Only_Crosstab.[200437], qryShpAndTeamAD1Only_Crosstab.[200436]
FROM qryShpAndTeamAD1Only_Crosstab;
year 2003 thru the present. One of the fields is a week number, YrWk, where
200420 denotes the 20th week of the year 2004.
The first query is a filtering query which limits the data to a specific
team code and time frame. In this instance the team is AD1 and the time
frame is >#12/13/2003#.
Next is a crosstab query based on the above query. This lists the data by
item number and sum of YrWl
The next query is based on the crosstab query above. This displays the item
number, the total for the timeframe, and the latest 15 weeks of shipments.
I would like to add a calculated filed in this query which will give the
AVERAGE weekly shipments of the last 15 weeks of shipments. Into a blank
filed I enter the following:
Ship15: Avg([200450]+[200449]+[200448]) and so on .
When I run the query I get the following message:
“You tried to execute a query that doesn’t include the specified expression
‘MtlNmbr’ as part of the aggregate function.â€
Is it possible to do what I want, or are there other steps which must be
taken?
The SQLs follow:
Query 1
SELECT tblShpngLines.MtlNmbr, tblShpngLines.PostingDate,
tblShpngLines.Descrip, tblShpngLines.Qty, tblItemData.MRPCntr,
tblShpngLines.YrWk
FROM tblShpngLines INNER JOIN tblItemData ON tblShpngLines.MtlNmbr =
tblItemData.MaterialNbr
WHERE (((tblShpngLines.PostingDate)>#12/13/2003#) AND
((tblItemData.MRPCntr)="AD1"))
ORDER BY tblShpngLines.YrWk DESC;
Crosstab query
TRANSFORM Sum(qryShpAndTeamAD1Only.Qty) AS [The Value]
SELECT qryShpAndTeamAD1Only.MtlNmbr, Sum(qryShpAndTeamAD1Only.Qty) AS [Total
Of Qty]
FROM qryShpAndTeamAD1Only
GROUP BY qryShpAndTeamAD1Only.MtlNmbr
ORDER BY qryShpAndTeamAD1Only.YrWk DESC
PIVOT qryShpAndTeamAD1Only.YrWk;
Last query
SELECT qryShpAndTeamAD1Only_Crosstab.MtlNmbr,
qryShpAndTeamAD1Only_Crosstab.[Total Of Qty],
qryShpAndTeamAD1Only_Crosstab.[200450],
qryShpAndTeamAD1Only_Crosstab.[200449],
qryShpAndTeamAD1Only_Crosstab.[200448],
qryShpAndTeamAD1Only_Crosstab.[200447],
qryShpAndTeamAD1Only_Crosstab.[200446],
qryShpAndTeamAD1Only_Crosstab.[200445],
qryShpAndTeamAD1Only_Crosstab.[200444],
qryShpAndTeamAD1Only_Crosstab.[200443],
qryShpAndTeamAD1Only_Crosstab.[200442],
qryShpAndTeamAD1Only_Crosstab.[200441],
qryShpAndTeamAD1Only_Crosstab.[200440],
qryShpAndTeamAD1Only_Crosstab.[200439],
qryShpAndTeamAD1Only_Crosstab.[200438],
qryShpAndTeamAD1Only_Crosstab.[200437], qryShpAndTeamAD1Only_Crosstab.[200436]
FROM qryShpAndTeamAD1Only_Crosstab;