Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsFormsForms ProgrammingQueriesModules / DAO / VBAReports / PrintingMacrosDatabase DesignSecurityConversionImporting / LinkingSQL Server / ADPMultiuser / NetworkingReplicationSetup / ConfigurationDeveloper ToolkitsActiveX ControlsNew UsersGeneral 1General 2
Access DirectoryToolsTutorialsUser Groups
Related Topics
SQL ServerOther DB ProductsMS OfficeMore Topics ...

MS Access Forum / Queries / February 2008

Tip: Looking for answers? Try searching our database.

Calculate after Grouping

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
leejayd@gmail.com - 02 Feb 2008 19:25 GMT
I have the Group By query below :

SELECT "Price" AS CALC_KPI, tblGroup.GroupName, tblData.Time,
Sum([tblData].[Value]/[tblData_1].[Value]) AS [Value]
FROM (tblGroup INNER JOIN tblRegion ON tblGroup.GroupID =
tblRegion.GroupID) INNER JOIN (tblPlants INNER JOIN (tblData INNER
JOIN tblData AS tblData_1 ON (tblData.Time = tblData_1.Time) AND
(tblData.PlantID = tblData_1.PlantID) AND (tblData.VersionID =
tblData_1.VersionID)) ON tblPlants.PlantID = tblData.PlantID) ON
tblRegion.RegionID = tblPlants.RegionID
GROUP BY "Price", tblGroup.GroupName, tblData.Time, tblData.VersionID,
tblData.LineItemID, tblData_1.LineItemID
HAVING (((tblData.VersionID)=1) AND ((tblData.LineItemID)=2) AND
((tblData_1.LineItemID)=1));

In this query I am calculating a Price KPI  (Sum([tblData].[Value]/
[tblData_1].[Value]) AS [Value])

Using the LineItems referenced in the HAVING clause.

My problem is that I want the calculation to divide after the records
have been aggregated.  Instread I seem to be only able to Aggregate
after the Division hence I get prices added together which is wrong.
Is there a solution to this problem?
Marshall Barton - 02 Feb 2008 21:26 GMT
>I have the Group By query below :
>
[quoted text clipped - 19 lines]
>have been aggregated.  Instread I seem to be only able to Aggregate
>after the Division hence I get prices added together which is wrong.

I this what you want?

Sum([tblData].[Value]) / Sum([tblData_1].[Value]) AS [Value]

Whether that's it or not, the HAVING clause should be a
WHERE clause (stupid query designer).

Signature

Marsh
MVP [MS Access]

 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.