Weighted Calculations

  • Thread starter Thread starter TYSITC
  • Start date Start date
T

TYSITC

I'm trying to total an aggregate function in a report. Here's the basics.

UnitIn- UnitOut - Yield - WtYield
10100 - 10000 - 99.01% - 90.01%
2000 - 1000 - 50% - 4.55%
Totals
12100 - 11000 - N/A - 94.56%

WtYield =UnitOut/sum([UnitOut])

=sum([WtYield]) does not work. These calculations are taking place in a
report. I tried to make it happen in a query, but due to the group by
requirement in the query in order to show all the proper fields (not shown
here in interest of brevity) for the report it doesn't sum up the LBSProd
properly.

Is there a way to remove the Group By in the query, and still have the data
show in a report perhaps?

Any ideas?
 
Post the SQL of your query as you have it now. Open query in design view,
click on VIEW - SQL View, highlight all, copy, and paste in a post.
 
SELECT [Prod Report Master Data].Date, [Prod Report Master Data].[ITEM No],
[Prod Report Master Data].Brand, [Prod Report Master Data].Description, [Prod
Report Master Data].[Line#], [Prod Report Master Data].[CS PRODUCED], [Prod
Report Master Data].[CS WT], [Prod Report Master Data].[Pounds to Line],
[Prod Report Master Data].[Production Weight], [Prod Report Master
Data].[Start Time], [Prod Report Master Data].[End Time], [Prod Report Master
Data].TotalTime, [Prod Report Master Data].Yield, [Prod Report Master
Data].[Opt Yield]
FROM [Prod Report Master Data]
GROUP BY [Prod Report Master Data].Date, [Prod Report Master Data].[ITEM
No], [Prod Report Master Data].Brand, [Prod Report Master Data].Description,
[Prod Report Master Data].[Line#], [Prod Report Master Data].[CS PRODUCED],
[Prod Report Master Data].[CS WT], [Prod Report Master Data].[Pounds to
Line], [Prod Report Master Data].[Production Weight], [Prod Report Master
Data].[Start Time], [Prod Report Master Data].[End Time], [Prod Report Master
Data].TotalTime, [Prod Report Master Data].Yield, [Prod Report Master
Data].[Opt Yield]
HAVING ((([Prod Report Master Data].Date)=[Production Date]));

KARL DEWEY said:
Post the SQL of your query as you have it now. Open query in design view,
click on VIEW - SQL View, highlight all, copy, and paste in a post.
--
Build a little, test a little.


TYSITC said:
I'm trying to total an aggregate function in a report. Here's the basics.

UnitIn- UnitOut - Yield - WtYield
10100 - 10000 - 99.01% - 90.01%
2000 - 1000 - 50% - 4.55%
Totals
12100 - 11000 - N/A - 94.56%

WtYield =UnitOut/sum([UnitOut])

=sum([WtYield]) does not work. These calculations are taking place in a
report. I tried to make it happen in a query, but due to the group by
requirement in the query in order to show all the proper fields (not shown
here in interest of brevity) for the report it doesn't sum up the LBSProd
properly.

Is there a way to remove the Group By in the query, and still have the data
show in a report perhaps?

Any ideas?
 
Are you sure you posted the correct SQL as I can not find LBSProd, UnitIn,
UnitOut, Yield, or WtYield within the query.

--
Build a little, test a little.


TYSITC said:
SELECT [Prod Report Master Data].Date, [Prod Report Master Data].[ITEM No],
[Prod Report Master Data].Brand, [Prod Report Master Data].Description, [Prod
Report Master Data].[Line#], [Prod Report Master Data].[CS PRODUCED], [Prod
Report Master Data].[CS WT], [Prod Report Master Data].[Pounds to Line],
[Prod Report Master Data].[Production Weight], [Prod Report Master
Data].[Start Time], [Prod Report Master Data].[End Time], [Prod Report Master
Data].TotalTime, [Prod Report Master Data].Yield, [Prod Report Master
Data].[Opt Yield]
FROM [Prod Report Master Data]
GROUP BY [Prod Report Master Data].Date, [Prod Report Master Data].[ITEM
No], [Prod Report Master Data].Brand, [Prod Report Master Data].Description,
[Prod Report Master Data].[Line#], [Prod Report Master Data].[CS PRODUCED],
[Prod Report Master Data].[CS WT], [Prod Report Master Data].[Pounds to
Line], [Prod Report Master Data].[Production Weight], [Prod Report Master
Data].[Start Time], [Prod Report Master Data].[End Time], [Prod Report Master
Data].TotalTime, [Prod Report Master Data].Yield, [Prod Report Master
Data].[Opt Yield]
HAVING ((([Prod Report Master Data].Date)=[Production Date]));

KARL DEWEY said:
Post the SQL of your query as you have it now. Open query in design view,
click on VIEW - SQL View, highlight all, copy, and paste in a post.
--
Build a little, test a little.


TYSITC said:
I'm trying to total an aggregate function in a report. Here's the basics.

UnitIn- UnitOut - Yield - WtYield
10100 - 10000 - 99.01% - 90.01%
2000 - 1000 - 50% - 4.55%
Totals
12100 - 11000 - N/A - 94.56%

WtYield =UnitOut/sum([UnitOut])

=sum([WtYield]) does not work. These calculations are taking place in a
report. I tried to make it happen in a query, but due to the group by
requirement in the query in order to show all the proper fields (not shown
here in interest of brevity) for the report it doesn't sum up the LBSProd
properly.

Is there a way to remove the Group By in the query, and still have the data
show in a report perhaps?

Any ideas?
 
I simplified the field names for the purpose of the question. Here's my
attempts to do the calculation, but it sums on the individual records, and I
need it to sum [Production Weight] per [Line#] value.

SELECT [Prod Report Master Data].Date, [Prod Report Master Data].[ITEM No],
[Prod Report Master Data].Brand, [Prod Report Master Data].Description, [Prod
Report Master Data].[Line#], [Prod Report Master Data].[CS PRODUCED], [Prod
Report Master Data].[CS WT], [Prod Report Master Data].[Pounds to Line],
[Prod Report Master Data].[Production Weight], [Prod Report Master
Data].[Start Time], [Prod Report Master Data].[End Time], [Prod Report Master
Data].TotalTime, [Prod Report Master Data].Yield, [Prod Report Master
Data].[Opt Yield], Sum([Prod Report Master Data].[Production Weight]) AS
ProdWtSub
FROM [Prod Report Master Data]
GROUP BY [Prod Report Master Data].Date, [Prod Report Master Data].[ITEM
No], [Prod Report Master Data].Brand, [Prod Report Master Data].Description,
[Prod Report Master Data].[Line#], [Prod Report Master Data].[CS PRODUCED],
[Prod Report Master Data].[CS WT], [Prod Report Master Data].[Pounds to
Line], [Prod Report Master Data].[Production Weight], [Prod Report Master
Data].[Start Time], [Prod Report Master Data].[End Time], [Prod Report Master
Data].TotalTime, [Prod Report Master Data].Yield, [Prod Report Master
Data].[Opt Yield]
HAVING ((([Prod Report Master Data].Date)=[Production Date]));


KARL DEWEY said:
Are you sure you posted the correct SQL as I can not find LBSProd, UnitIn,
UnitOut, Yield, or WtYield within the query.

--
Build a little, test a little.


TYSITC said:
SELECT [Prod Report Master Data].Date, [Prod Report Master Data].[ITEM No],
[Prod Report Master Data].Brand, [Prod Report Master Data].Description, [Prod
Report Master Data].[Line#], [Prod Report Master Data].[CS PRODUCED], [Prod
Report Master Data].[CS WT], [Prod Report Master Data].[Pounds to Line],
[Prod Report Master Data].[Production Weight], [Prod Report Master
Data].[Start Time], [Prod Report Master Data].[End Time], [Prod Report Master
Data].TotalTime, [Prod Report Master Data].Yield, [Prod Report Master
Data].[Opt Yield]
FROM [Prod Report Master Data]
GROUP BY [Prod Report Master Data].Date, [Prod Report Master Data].[ITEM
No], [Prod Report Master Data].Brand, [Prod Report Master Data].Description,
[Prod Report Master Data].[Line#], [Prod Report Master Data].[CS PRODUCED],
[Prod Report Master Data].[CS WT], [Prod Report Master Data].[Pounds to
Line], [Prod Report Master Data].[Production Weight], [Prod Report Master
Data].[Start Time], [Prod Report Master Data].[End Time], [Prod Report Master
Data].TotalTime, [Prod Report Master Data].Yield, [Prod Report Master
Data].[Opt Yield]
HAVING ((([Prod Report Master Data].Date)=[Production Date]));

KARL DEWEY said:
Post the SQL of your query as you have it now. Open query in design view,
click on VIEW - SQL View, highlight all, copy, and paste in a post.
--
Build a little, test a little.


:

I'm trying to total an aggregate function in a report. Here's the basics.

UnitIn- UnitOut - Yield - WtYield
10100 - 10000 - 99.01% - 90.01%
2000 - 1000 - 50% - 4.55%
Totals
12100 - 11000 - N/A - 94.56%

WtYield =UnitOut/sum([UnitOut])

=sum([WtYield]) does not work. These calculations are taking place in a
report. I tried to make it happen in a query, but due to the group by
requirement in the query in order to show all the proper fields (not shown
here in interest of brevity) for the report it doesn't sum up the LBSProd
properly.

Is there a way to remove the Group By in the query, and still have the data
show in a report perhaps?

Any ideas?
 
You can not total and have individual weights at the same time.

I am still learning subqueries and did not test this --
SELECT [Prod Report Master Data].Date, [Prod Report Master Data].[ITEM No],
[Prod Report Master Data].Brand, [Prod Report Master Data].Description, [Prod
Report Master Data].[Line#], [Prod Report Master Data].[CS PRODUCED], [Prod
Report Master Data].[CS WT], [Prod Report Master Data].[Pounds to Line],
[Prod Report Master Data].[Production Weight], [Prod Report Master
Data].[Start Time], [Prod Report Master Data].[End Time], [Prod Report Master
Data].TotalTime, [Prod Report Master Data].Yield, [Prod Report Master
Data].[Opt Yield], (SELECT Sum([Prod Report Master Data].[Production Weight]
FROM [Prod Report Master Data] AS [AA] WHERE [AA].[Line#] = [Prod Report
Master Data].[Line#]) AS ProdWtSub
FROM [Prod Report Master Data]
HAVING ((([Prod Report Master Data].Date)=[Production Date]));

You can build a separate query for the totals and join it on the Line#.

--
Build a little, test a little.


TYSITC said:
I simplified the field names for the purpose of the question. Here's my
attempts to do the calculation, but it sums on the individual records, and I
need it to sum [Production Weight] per [Line#] value.

SELECT [Prod Report Master Data].Date, [Prod Report Master Data].[ITEM No],
[Prod Report Master Data].Brand, [Prod Report Master Data].Description, [Prod
Report Master Data].[Line#], [Prod Report Master Data].[CS PRODUCED], [Prod
Report Master Data].[CS WT], [Prod Report Master Data].[Pounds to Line],
[Prod Report Master Data].[Production Weight], [Prod Report Master
Data].[Start Time], [Prod Report Master Data].[End Time], [Prod Report Master
Data].TotalTime, [Prod Report Master Data].Yield, [Prod Report Master
Data].[Opt Yield], Sum([Prod Report Master Data].[Production Weight]) AS
ProdWtSub
FROM [Prod Report Master Data]
GROUP BY [Prod Report Master Data].Date, [Prod Report Master Data].[ITEM
No], [Prod Report Master Data].Brand, [Prod Report Master Data].Description,
[Prod Report Master Data].[Line#], [Prod Report Master Data].[CS PRODUCED],
[Prod Report Master Data].[CS WT], [Prod Report Master Data].[Pounds to
Line], [Prod Report Master Data].[Production Weight], [Prod Report Master
Data].[Start Time], [Prod Report Master Data].[End Time], [Prod Report Master
Data].TotalTime, [Prod Report Master Data].Yield, [Prod Report Master
Data].[Opt Yield]
HAVING ((([Prod Report Master Data].Date)=[Production Date]));


KARL DEWEY said:
Are you sure you posted the correct SQL as I can not find LBSProd, UnitIn,
UnitOut, Yield, or WtYield within the query.

--
Build a little, test a little.


TYSITC said:
SELECT [Prod Report Master Data].Date, [Prod Report Master Data].[ITEM No],
[Prod Report Master Data].Brand, [Prod Report Master Data].Description, [Prod
Report Master Data].[Line#], [Prod Report Master Data].[CS PRODUCED], [Prod
Report Master Data].[CS WT], [Prod Report Master Data].[Pounds to Line],
[Prod Report Master Data].[Production Weight], [Prod Report Master
Data].[Start Time], [Prod Report Master Data].[End Time], [Prod Report Master
Data].TotalTime, [Prod Report Master Data].Yield, [Prod Report Master
Data].[Opt Yield]
FROM [Prod Report Master Data]
GROUP BY [Prod Report Master Data].Date, [Prod Report Master Data].[ITEM
No], [Prod Report Master Data].Brand, [Prod Report Master Data].Description,
[Prod Report Master Data].[Line#], [Prod Report Master Data].[CS PRODUCED],
[Prod Report Master Data].[CS WT], [Prod Report Master Data].[Pounds to
Line], [Prod Report Master Data].[Production Weight], [Prod Report Master
Data].[Start Time], [Prod Report Master Data].[End Time], [Prod Report Master
Data].TotalTime, [Prod Report Master Data].Yield, [Prod Report Master
Data].[Opt Yield]
HAVING ((([Prod Report Master Data].Date)=[Production Date]));

:

Post the SQL of your query as you have it now. Open query in design view,
click on VIEW - SQL View, highlight all, copy, and paste in a post.
--
Build a little, test a little.


:

I'm trying to total an aggregate function in a report. Here's the basics.

UnitIn- UnitOut - Yield - WtYield
10100 - 10000 - 99.01% - 90.01%
2000 - 1000 - 50% - 4.55%
Totals
12100 - 11000 - N/A - 94.56%

WtYield =UnitOut/sum([UnitOut])

=sum([WtYield]) does not work. These calculations are taking place in a
report. I tried to make it happen in a query, but due to the group by
requirement in the query in order to show all the proper fields (not shown
here in interest of brevity) for the report it doesn't sum up the LBSProd
properly.

Is there a way to remove the Group By in the query, and still have the data
show in a report perhaps?

Any ideas?
 
There is a syntax error in this. A missing ), or ] that I can't seem to find.

KARL DEWEY said:
You can not total and have individual weights at the same time.

I am still learning subqueries and did not test this --
SELECT [Prod Report Master Data].Date, [Prod Report Master Data].[ITEM No],
[Prod Report Master Data].Brand, [Prod Report Master Data].Description, [Prod
Report Master Data].[Line#], [Prod Report Master Data].[CS PRODUCED], [Prod
Report Master Data].[CS WT], [Prod Report Master Data].[Pounds to Line],
[Prod Report Master Data].[Production Weight], [Prod Report Master
Data].[Start Time], [Prod Report Master Data].[End Time], [Prod Report Master
Data].TotalTime, [Prod Report Master Data].Yield, [Prod Report Master
Data].[Opt Yield], (SELECT Sum([Prod Report Master Data].[Production Weight]
FROM [Prod Report Master Data] AS [AA] WHERE [AA].[Line#] = [Prod Report
Master Data].[Line#]) AS ProdWtSub
FROM [Prod Report Master Data]
HAVING ((([Prod Report Master Data].Date)=[Production Date]));

You can build a separate query for the totals and join it on the Line#.

--
Build a little, test a little.


TYSITC said:
I simplified the field names for the purpose of the question. Here's my
attempts to do the calculation, but it sums on the individual records, and I
need it to sum [Production Weight] per [Line#] value.

SELECT [Prod Report Master Data].Date, [Prod Report Master Data].[ITEM No],
[Prod Report Master Data].Brand, [Prod Report Master Data].Description, [Prod
Report Master Data].[Line#], [Prod Report Master Data].[CS PRODUCED], [Prod
Report Master Data].[CS WT], [Prod Report Master Data].[Pounds to Line],
[Prod Report Master Data].[Production Weight], [Prod Report Master
Data].[Start Time], [Prod Report Master Data].[End Time], [Prod Report Master
Data].TotalTime, [Prod Report Master Data].Yield, [Prod Report Master
Data].[Opt Yield], Sum([Prod Report Master Data].[Production Weight]) AS
ProdWtSub
FROM [Prod Report Master Data]
GROUP BY [Prod Report Master Data].Date, [Prod Report Master Data].[ITEM
No], [Prod Report Master Data].Brand, [Prod Report Master Data].Description,
[Prod Report Master Data].[Line#], [Prod Report Master Data].[CS PRODUCED],
[Prod Report Master Data].[CS WT], [Prod Report Master Data].[Pounds to
Line], [Prod Report Master Data].[Production Weight], [Prod Report Master
Data].[Start Time], [Prod Report Master Data].[End Time], [Prod Report Master
Data].TotalTime, [Prod Report Master Data].Yield, [Prod Report Master
Data].[Opt Yield]
HAVING ((([Prod Report Master Data].Date)=[Production Date]));


KARL DEWEY said:
Are you sure you posted the correct SQL as I can not find LBSProd, UnitIn,
UnitOut, Yield, or WtYield within the query.

--
Build a little, test a little.


:

SELECT [Prod Report Master Data].Date, [Prod Report Master Data].[ITEM No],
[Prod Report Master Data].Brand, [Prod Report Master Data].Description, [Prod
Report Master Data].[Line#], [Prod Report Master Data].[CS PRODUCED], [Prod
Report Master Data].[CS WT], [Prod Report Master Data].[Pounds to Line],
[Prod Report Master Data].[Production Weight], [Prod Report Master
Data].[Start Time], [Prod Report Master Data].[End Time], [Prod Report Master
Data].TotalTime, [Prod Report Master Data].Yield, [Prod Report Master
Data].[Opt Yield]
FROM [Prod Report Master Data]
GROUP BY [Prod Report Master Data].Date, [Prod Report Master Data].[ITEM
No], [Prod Report Master Data].Brand, [Prod Report Master Data].Description,
[Prod Report Master Data].[Line#], [Prod Report Master Data].[CS PRODUCED],
[Prod Report Master Data].[CS WT], [Prod Report Master Data].[Pounds to
Line], [Prod Report Master Data].[Production Weight], [Prod Report Master
Data].[Start Time], [Prod Report Master Data].[End Time], [Prod Report Master
Data].TotalTime, [Prod Report Master Data].Yield, [Prod Report Master
Data].[Opt Yield]
HAVING ((([Prod Report Master Data].Date)=[Production Date]));

:

Post the SQL of your query as you have it now. Open query in design view,
click on VIEW - SQL View, highlight all, copy, and paste in a post.
--
Build a little, test a little.


:

I'm trying to total an aggregate function in a report. Here's the basics.

UnitIn- UnitOut - Yield - WtYield
10100 - 10000 - 99.01% - 90.01%
2000 - 1000 - 50% - 4.55%
Totals
12100 - 11000 - N/A - 94.56%

WtYield =UnitOut/sum([UnitOut])

=sum([WtYield]) does not work. These calculations are taking place in a
report. I tried to make it happen in a query, but due to the group by
requirement in the query in order to show all the proper fields (not shown
here in interest of brevity) for the report it doesn't sum up the LBSProd
properly.

Is there a way to remove the Group By in the query, and still have the data
show in a report perhaps?

Any ideas?
 
It need to be just before the FROM in the subquery like this --
(SELECT Sum([Prod Report Master Data].[Production Weight]) FROM [Prod
Report Master Data] AS [AA] WHERE [AA].[Line#] = [Prod Report Master
Data].[Line#]) AS ProdWtSub

--
Build a little, test a little.


TYSITC said:
There is a syntax error in this. A missing ), or ] that I can't seem to find.

KARL DEWEY said:
You can not total and have individual weights at the same time.

I am still learning subqueries and did not test this --
SELECT [Prod Report Master Data].Date, [Prod Report Master Data].[ITEM No],
[Prod Report Master Data].Brand, [Prod Report Master Data].Description, [Prod
Report Master Data].[Line#], [Prod Report Master Data].[CS PRODUCED], [Prod
Report Master Data].[CS WT], [Prod Report Master Data].[Pounds to Line],
[Prod Report Master Data].[Production Weight], [Prod Report Master
Data].[Start Time], [Prod Report Master Data].[End Time], [Prod Report Master
Data].TotalTime, [Prod Report Master Data].Yield, [Prod Report Master
Data].[Opt Yield], (SELECT Sum([Prod Report Master Data].[Production Weight]
FROM [Prod Report Master Data] AS [AA] WHERE [AA].[Line#] = [Prod Report
Master Data].[Line#]) AS ProdWtSub
FROM [Prod Report Master Data]
HAVING ((([Prod Report Master Data].Date)=[Production Date]));

You can build a separate query for the totals and join it on the Line#.

--
Build a little, test a little.


TYSITC said:
I simplified the field names for the purpose of the question. Here's my
attempts to do the calculation, but it sums on the individual records, and I
need it to sum [Production Weight] per [Line#] value.

SELECT [Prod Report Master Data].Date, [Prod Report Master Data].[ITEM No],
[Prod Report Master Data].Brand, [Prod Report Master Data].Description, [Prod
Report Master Data].[Line#], [Prod Report Master Data].[CS PRODUCED], [Prod
Report Master Data].[CS WT], [Prod Report Master Data].[Pounds to Line],
[Prod Report Master Data].[Production Weight], [Prod Report Master
Data].[Start Time], [Prod Report Master Data].[End Time], [Prod Report Master
Data].TotalTime, [Prod Report Master Data].Yield, [Prod Report Master
Data].[Opt Yield], Sum([Prod Report Master Data].[Production Weight]) AS
ProdWtSub
FROM [Prod Report Master Data]
GROUP BY [Prod Report Master Data].Date, [Prod Report Master Data].[ITEM
No], [Prod Report Master Data].Brand, [Prod Report Master Data].Description,
[Prod Report Master Data].[Line#], [Prod Report Master Data].[CS PRODUCED],
[Prod Report Master Data].[CS WT], [Prod Report Master Data].[Pounds to
Line], [Prod Report Master Data].[Production Weight], [Prod Report Master
Data].[Start Time], [Prod Report Master Data].[End Time], [Prod Report Master
Data].TotalTime, [Prod Report Master Data].Yield, [Prod Report Master
Data].[Opt Yield]
HAVING ((([Prod Report Master Data].Date)=[Production Date]));


:

Are you sure you posted the correct SQL as I can not find LBSProd, UnitIn,
UnitOut, Yield, or WtYield within the query.

--
Build a little, test a little.


:

SELECT [Prod Report Master Data].Date, [Prod Report Master Data].[ITEM No],
[Prod Report Master Data].Brand, [Prod Report Master Data].Description, [Prod
Report Master Data].[Line#], [Prod Report Master Data].[CS PRODUCED], [Prod
Report Master Data].[CS WT], [Prod Report Master Data].[Pounds to Line],
[Prod Report Master Data].[Production Weight], [Prod Report Master
Data].[Start Time], [Prod Report Master Data].[End Time], [Prod Report Master
Data].TotalTime, [Prod Report Master Data].Yield, [Prod Report Master
Data].[Opt Yield]
FROM [Prod Report Master Data]
GROUP BY [Prod Report Master Data].Date, [Prod Report Master Data].[ITEM
No], [Prod Report Master Data].Brand, [Prod Report Master Data].Description,
[Prod Report Master Data].[Line#], [Prod Report Master Data].[CS PRODUCED],
[Prod Report Master Data].[CS WT], [Prod Report Master Data].[Pounds to
Line], [Prod Report Master Data].[Production Weight], [Prod Report Master
Data].[Start Time], [Prod Report Master Data].[End Time], [Prod Report Master
Data].TotalTime, [Prod Report Master Data].Yield, [Prod Report Master
Data].[Opt Yield]
HAVING ((([Prod Report Master Data].Date)=[Production Date]));

:

Post the SQL of your query as you have it now. Open query in design view,
click on VIEW - SQL View, highlight all, copy, and paste in a post.
--
Build a little, test a little.


:

I'm trying to total an aggregate function in a report. Here's the basics.

UnitIn- UnitOut - Yield - WtYield
10100 - 10000 - 99.01% - 90.01%
2000 - 1000 - 50% - 4.55%
Totals
12100 - 11000 - N/A - 94.56%

WtYield =UnitOut/sum([UnitOut])

=sum([WtYield]) does not work. These calculations are taking place in a
report. I tried to make it happen in a query, but due to the group by
requirement in the query in order to show all the proper fields (not shown
here in interest of brevity) for the report it doesn't sum up the LBSProd
properly.

Is there a way to remove the Group By in the query, and still have the data
show in a report perhaps?

Any ideas?
 
Back
Top