Calculation wrong in sum query

H

HeatherD25

I think this should be a simple query to do, but I can't get the sum values
correct. Here's my query:

SELECT qRpt_EmployeeCOS_1.EmployeeID, Sum(qRpt_EmployeeCOS_1.[MonthlyCOS])
AS SumOfMonthlyCOS
FROM qRpt_EmployeeCOS_1
GROUP BY qRpt_EmployeeCOS_1.EmployeeID;

I just want a sum of MonthlyCOS by each employee. When I run the report,
the sums are completely off. Also, when I changed the sum to a count it also
returned the wrong value -- it came back with 14 when it should only have
been 5. Any ideas?

Thanks,
Heather
 
K

Klatuu

How many employees do you have in the table?
What data type is [MonthlyCOS]?

Can [MonthlyCOS] ever have a Null value?
 
H

HeatherD25

There are 192 employees -- they each have 5 entries in the underlying query
(qRpt_EmployeeCOS_1) -- 1 entry for each month for January - May. MonthlyCOS
is supposed to be a currency data type -- it's a calculation on the
underlying query. I never specify it as a currency, but the items ini the
calculation are either number or currency data types. MonthlyCOS will never
have a Null value.

Thanks!
Heather

Klatuu said:
How many employees do you have in the table?
What data type is [MonthlyCOS]?

Can [MonthlyCOS] ever have a Null value?
--
Dave Hargis, Microsoft Access MVP


HeatherD25 said:
I think this should be a simple query to do, but I can't get the sum values
correct. Here's my query:

SELECT qRpt_EmployeeCOS_1.EmployeeID, Sum(qRpt_EmployeeCOS_1.[MonthlyCOS])
AS SumOfMonthlyCOS
FROM qRpt_EmployeeCOS_1
GROUP BY qRpt_EmployeeCOS_1.EmployeeID;

I just want a sum of MonthlyCOS by each employee. When I run the report,
the sums are completely off. Also, when I changed the sum to a count it also
returned the wrong value -- it came back with 14 when it should only have
been 5. Any ideas?

Thanks,
Heather
 
K

Klatuu

Then your query would be expected to return 192 rows, not 5.
You are grouping by EmployeeID and summing the MonthlyCOS field.
What is the underlying query doing? Have you validated it is working
correctly?
--
Dave Hargis, Microsoft Access MVP


HeatherD25 said:
There are 192 employees -- they each have 5 entries in the underlying query
(qRpt_EmployeeCOS_1) -- 1 entry for each month for January - May. MonthlyCOS
is supposed to be a currency data type -- it's a calculation on the
underlying query. I never specify it as a currency, but the items ini the
calculation are either number or currency data types. MonthlyCOS will never
have a Null value.

Thanks!
Heather

Klatuu said:
How many employees do you have in the table?
What data type is [MonthlyCOS]?

Can [MonthlyCOS] ever have a Null value?
--
Dave Hargis, Microsoft Access MVP


HeatherD25 said:
I think this should be a simple query to do, but I can't get the sum values
correct. Here's my query:

SELECT qRpt_EmployeeCOS_1.EmployeeID, Sum(qRpt_EmployeeCOS_1.[MonthlyCOS])
AS SumOfMonthlyCOS
FROM qRpt_EmployeeCOS_1
GROUP BY qRpt_EmployeeCOS_1.EmployeeID;

I just want a sum of MonthlyCOS by each employee. When I run the report,
the sums are completely off. Also, when I changed the sum to a count it also
returned the wrong value -- it came back with 14 when it should only have
been 5. Any ideas?

Thanks,
Heather
 
H

HeatherD25

The underlying query seems to be working correctly for the few employees I've
checked.

I basically just want a total for the "MonthlyCOS" for each Employee.
Basically, what is their "MonthlyCOS" for the year so far? I thought I could
have the underlying query sum it up by month -- which is working. Now I just
need to sum the months together to come up with a total? Am I off track with
what I'm trying to do?

Thanks!!

Klatuu said:
Then your query would be expected to return 192 rows, not 5.
You are grouping by EmployeeID and summing the MonthlyCOS field.
What is the underlying query doing? Have you validated it is working
correctly?
--
Dave Hargis, Microsoft Access MVP


HeatherD25 said:
There are 192 employees -- they each have 5 entries in the underlying query
(qRpt_EmployeeCOS_1) -- 1 entry for each month for January - May. MonthlyCOS
is supposed to be a currency data type -- it's a calculation on the
underlying query. I never specify it as a currency, but the items ini the
calculation are either number or currency data types. MonthlyCOS will never
have a Null value.

Thanks!
Heather

Klatuu said:
How many employees do you have in the table?
What data type is [MonthlyCOS]?

Can [MonthlyCOS] ever have a Null value?
--
Dave Hargis, Microsoft Access MVP


:

I think this should be a simple query to do, but I can't get the sum values
correct. Here's my query:

SELECT qRpt_EmployeeCOS_1.EmployeeID, Sum(qRpt_EmployeeCOS_1.[MonthlyCOS])
AS SumOfMonthlyCOS
FROM qRpt_EmployeeCOS_1
GROUP BY qRpt_EmployeeCOS_1.EmployeeID;

I just want a sum of MonthlyCOS by each employee. When I run the report,
the sums are completely off. Also, when I changed the sum to a count it also
returned the wrong value -- it came back with 14 when it should only have
been 5. Any ideas?

Thanks,
Heather
 
K

Klatuu

What is the layout of the table you are starting with?
Where does MonthlyCOS come from? If you can help me understand your table
structure, I think we can get it to work for you.
--
Dave Hargis, Microsoft Access MVP


HeatherD25 said:
The underlying query seems to be working correctly for the few employees I've
checked.

I basically just want a total for the "MonthlyCOS" for each Employee.
Basically, what is their "MonthlyCOS" for the year so far? I thought I could
have the underlying query sum it up by month -- which is working. Now I just
need to sum the months together to come up with a total? Am I off track with
what I'm trying to do?

Thanks!!

Klatuu said:
Then your query would be expected to return 192 rows, not 5.
You are grouping by EmployeeID and summing the MonthlyCOS field.
What is the underlying query doing? Have you validated it is working
correctly?
--
Dave Hargis, Microsoft Access MVP


HeatherD25 said:
There are 192 employees -- they each have 5 entries in the underlying query
(qRpt_EmployeeCOS_1) -- 1 entry for each month for January - May. MonthlyCOS
is supposed to be a currency data type -- it's a calculation on the
underlying query. I never specify it as a currency, but the items ini the
calculation are either number or currency data types. MonthlyCOS will never
have a Null value.

Thanks!
Heather

:

How many employees do you have in the table?
What data type is [MonthlyCOS]?

Can [MonthlyCOS] ever have a Null value?
--
Dave Hargis, Microsoft Access MVP


:

I think this should be a simple query to do, but I can't get the sum values
correct. Here's my query:

SELECT qRpt_EmployeeCOS_1.EmployeeID, Sum(qRpt_EmployeeCOS_1.[MonthlyCOS])
AS SumOfMonthlyCOS
FROM qRpt_EmployeeCOS_1
GROUP BY qRpt_EmployeeCOS_1.EmployeeID;

I just want a sum of MonthlyCOS by each employee. When I run the report,
the sums are completely off. Also, when I changed the sum to a count it also
returned the wrong value -- it came back with 14 when it should only have
been 5. Any ideas?

Thanks,
Heather
 
H

HeatherD25

Thank you for your help!

Here are the tables that feed Query #1:
FullName (*EmployeeID, FirstName, LastName, MI, Full)
EmployeeRecord (*EmployeeID, DailyHours, Status, other misc. employee info)
PeriodLookUp (*PeriodID, CycleEndDate, Period, PeriodDays)
EmployeeCoS (*EmployeeID, *PeriodID, COS)

Here's the Query #1 SQL:
SELECT EmployeeRecord.EmployeeID, [Full Name].Full,
EmployeeRecord.DailyHours, PeriodLookUp.PeriodDays, PeriodLookUp.Period,
PeriodLookUp.CycleEndDate, ([DailyHours]*[PeriodDays]*([EmployeeCoS].[COS]))
AS MonthlyCOS, EmployeeCoS.COS
FROM ((EmployeeRecord INNER JOIN [Full Name] ON EmployeeRecord.EmployeeID =
[Full Name].EmployeeID) INNER JOIN (ProjectLookup INNER JOIN (PeriodLookUp
INNER JOIN EmployeeRevenue ON PeriodLookUp.Period = EmployeeRevenue.Period)
ON ProjectLookup.ProjectNumber = EmployeeRevenue.Project) ON
EmployeeRecord.EmployeeID = EmployeeRevenue.Emp_ID) INNER JOIN EmployeeCoS ON
(PeriodLookUp.PeriodID = EmployeeCoS.PeriodID) AND (EmployeeRecord.EmployeeID
= EmployeeCoS.EmployeeID);

This query should give me a line for each employee for each month with their
totalCOS for the month. This seems to be working and returning what I was
hoping for.

Then I have Query #2 that's based on Query #1:

SELECT qRpt_EmployeeCOS_1.EmployeeID, Sum(qRpt_EmployeeCOS_1.MonthlyCOS) AS
SumOfMonthlyCOS
FROM qRpt_EmployeeCOS_1
GROUP BY qRpt_EmployeeCOS_1.EmployeeID;

The total numbers it brings back aren't right -- if you add the numbers for
each employee from each month from the first query, then don't equal the
total on the 2nd query.

Thank you so much for your assistance!


Klatuu said:
What is the layout of the table you are starting with?
Where does MonthlyCOS come from? If you can help me understand your table
structure, I think we can get it to work for you.
--
Dave Hargis, Microsoft Access MVP


HeatherD25 said:
The underlying query seems to be working correctly for the few employees I've
checked.

I basically just want a total for the "MonthlyCOS" for each Employee.
Basically, what is their "MonthlyCOS" for the year so far? I thought I could
have the underlying query sum it up by month -- which is working. Now I just
need to sum the months together to come up with a total? Am I off track with
what I'm trying to do?

Thanks!!

Klatuu said:
Then your query would be expected to return 192 rows, not 5.
You are grouping by EmployeeID and summing the MonthlyCOS field.
What is the underlying query doing? Have you validated it is working
correctly?
--
Dave Hargis, Microsoft Access MVP


:

There are 192 employees -- they each have 5 entries in the underlying query
(qRpt_EmployeeCOS_1) -- 1 entry for each month for January - May. MonthlyCOS
is supposed to be a currency data type -- it's a calculation on the
underlying query. I never specify it as a currency, but the items ini the
calculation are either number or currency data types. MonthlyCOS will never
have a Null value.

Thanks!
Heather

:

How many employees do you have in the table?
What data type is [MonthlyCOS]?

Can [MonthlyCOS] ever have a Null value?
--
Dave Hargis, Microsoft Access MVP


:

I think this should be a simple query to do, but I can't get the sum values
correct. Here's my query:

SELECT qRpt_EmployeeCOS_1.EmployeeID, Sum(qRpt_EmployeeCOS_1.[MonthlyCOS])
AS SumOfMonthlyCOS
FROM qRpt_EmployeeCOS_1
GROUP BY qRpt_EmployeeCOS_1.EmployeeID;

I just want a sum of MonthlyCOS by each employee. When I run the report,
the sums are completely off. Also, when I changed the sum to a count it also
returned the wrong value -- it came back with 14 when it should only have
been 5. Any ideas?

Thanks,
Heather
 
K

Klatuu

I'm still suspicious of query 1.
I suggest you do some manual calculations by looking at the data in the
tables. Then verify you are getting the correct numbers.
I know you said it seems to be, but you need to be sure. Query 2 is so
simple and straight forward, unless I am missing something, I don't see it
being the problem.

It also seems all you need to get what you are wanting from query 2 is one
query using EmployeeCos, EmloyeeRecord, and PeriodLookup tables.

--
Dave Hargis, Microsoft Access MVP


HeatherD25 said:
Thank you for your help!

Here are the tables that feed Query #1:
FullName (*EmployeeID, FirstName, LastName, MI, Full)
EmployeeRecord (*EmployeeID, DailyHours, Status, other misc. employee info)
PeriodLookUp (*PeriodID, CycleEndDate, Period, PeriodDays)
EmployeeCoS (*EmployeeID, *PeriodID, COS)

Here's the Query #1 SQL:
SELECT EmployeeRecord.EmployeeID, [Full Name].Full,
EmployeeRecord.DailyHours, PeriodLookUp.PeriodDays, PeriodLookUp.Period,
PeriodLookUp.CycleEndDate, ([DailyHours]*[PeriodDays]*([EmployeeCoS].[COS]))
AS MonthlyCOS, EmployeeCoS.COS
FROM ((EmployeeRecord INNER JOIN [Full Name] ON EmployeeRecord.EmployeeID =
[Full Name].EmployeeID) INNER JOIN (ProjectLookup INNER JOIN (PeriodLookUp
INNER JOIN EmployeeRevenue ON PeriodLookUp.Period = EmployeeRevenue.Period)
ON ProjectLookup.ProjectNumber = EmployeeRevenue.Project) ON
EmployeeRecord.EmployeeID = EmployeeRevenue.Emp_ID) INNER JOIN EmployeeCoS ON
(PeriodLookUp.PeriodID = EmployeeCoS.PeriodID) AND (EmployeeRecord.EmployeeID
= EmployeeCoS.EmployeeID);

This query should give me a line for each employee for each month with their
totalCOS for the month. This seems to be working and returning what I was
hoping for.

Then I have Query #2 that's based on Query #1:

SELECT qRpt_EmployeeCOS_1.EmployeeID, Sum(qRpt_EmployeeCOS_1.MonthlyCOS) AS
SumOfMonthlyCOS
FROM qRpt_EmployeeCOS_1
GROUP BY qRpt_EmployeeCOS_1.EmployeeID;

The total numbers it brings back aren't right -- if you add the numbers for
each employee from each month from the first query, then don't equal the
total on the 2nd query.

Thank you so much for your assistance!


Klatuu said:
What is the layout of the table you are starting with?
Where does MonthlyCOS come from? If you can help me understand your table
structure, I think we can get it to work for you.
--
Dave Hargis, Microsoft Access MVP


HeatherD25 said:
The underlying query seems to be working correctly for the few employees I've
checked.

I basically just want a total for the "MonthlyCOS" for each Employee.
Basically, what is their "MonthlyCOS" for the year so far? I thought I could
have the underlying query sum it up by month -- which is working. Now I just
need to sum the months together to come up with a total? Am I off track with
what I'm trying to do?

Thanks!!

:

Then your query would be expected to return 192 rows, not 5.
You are grouping by EmployeeID and summing the MonthlyCOS field.
What is the underlying query doing? Have you validated it is working
correctly?
--
Dave Hargis, Microsoft Access MVP


:

There are 192 employees -- they each have 5 entries in the underlying query
(qRpt_EmployeeCOS_1) -- 1 entry for each month for January - May. MonthlyCOS
is supposed to be a currency data type -- it's a calculation on the
underlying query. I never specify it as a currency, but the items ini the
calculation are either number or currency data types. MonthlyCOS will never
have a Null value.

Thanks!
Heather

:

How many employees do you have in the table?
What data type is [MonthlyCOS]?

Can [MonthlyCOS] ever have a Null value?
--
Dave Hargis, Microsoft Access MVP


:

I think this should be a simple query to do, but I can't get the sum values
correct. Here's my query:

SELECT qRpt_EmployeeCOS_1.EmployeeID, Sum(qRpt_EmployeeCOS_1.[MonthlyCOS])
AS SumOfMonthlyCOS
FROM qRpt_EmployeeCOS_1
GROUP BY qRpt_EmployeeCOS_1.EmployeeID;

I just want a sum of MonthlyCOS by each employee. When I run the report,
the sums are completely off. Also, when I changed the sum to a count it also
returned the wrong value -- it came back with 14 when it should only have
been 5. Any ideas?

Thanks,
Heather
 
H

HeatherD25

It's working now... I just re-did the queries from scratch and it worked. I
must have had some extraneous piece of data in them before that was skewing
the results. Thank you so much for all of your help!!

Klatuu said:
I'm still suspicious of query 1.
I suggest you do some manual calculations by looking at the data in the
tables. Then verify you are getting the correct numbers.
I know you said it seems to be, but you need to be sure. Query 2 is so
simple and straight forward, unless I am missing something, I don't see it
being the problem.

It also seems all you need to get what you are wanting from query 2 is one
query using EmployeeCos, EmloyeeRecord, and PeriodLookup tables.

--
Dave Hargis, Microsoft Access MVP


HeatherD25 said:
Thank you for your help!

Here are the tables that feed Query #1:
FullName (*EmployeeID, FirstName, LastName, MI, Full)
EmployeeRecord (*EmployeeID, DailyHours, Status, other misc. employee info)
PeriodLookUp (*PeriodID, CycleEndDate, Period, PeriodDays)
EmployeeCoS (*EmployeeID, *PeriodID, COS)

Here's the Query #1 SQL:
SELECT EmployeeRecord.EmployeeID, [Full Name].Full,
EmployeeRecord.DailyHours, PeriodLookUp.PeriodDays, PeriodLookUp.Period,
PeriodLookUp.CycleEndDate, ([DailyHours]*[PeriodDays]*([EmployeeCoS].[COS]))
AS MonthlyCOS, EmployeeCoS.COS
FROM ((EmployeeRecord INNER JOIN [Full Name] ON EmployeeRecord.EmployeeID =
[Full Name].EmployeeID) INNER JOIN (ProjectLookup INNER JOIN (PeriodLookUp
INNER JOIN EmployeeRevenue ON PeriodLookUp.Period = EmployeeRevenue.Period)
ON ProjectLookup.ProjectNumber = EmployeeRevenue.Project) ON
EmployeeRecord.EmployeeID = EmployeeRevenue.Emp_ID) INNER JOIN EmployeeCoS ON
(PeriodLookUp.PeriodID = EmployeeCoS.PeriodID) AND (EmployeeRecord.EmployeeID
= EmployeeCoS.EmployeeID);

This query should give me a line for each employee for each month with their
totalCOS for the month. This seems to be working and returning what I was
hoping for.

Then I have Query #2 that's based on Query #1:

SELECT qRpt_EmployeeCOS_1.EmployeeID, Sum(qRpt_EmployeeCOS_1.MonthlyCOS) AS
SumOfMonthlyCOS
FROM qRpt_EmployeeCOS_1
GROUP BY qRpt_EmployeeCOS_1.EmployeeID;

The total numbers it brings back aren't right -- if you add the numbers for
each employee from each month from the first query, then don't equal the
total on the 2nd query.

Thank you so much for your assistance!


Klatuu said:
What is the layout of the table you are starting with?
Where does MonthlyCOS come from? If you can help me understand your table
structure, I think we can get it to work for you.
--
Dave Hargis, Microsoft Access MVP


:

The underlying query seems to be working correctly for the few employees I've
checked.

I basically just want a total for the "MonthlyCOS" for each Employee.
Basically, what is their "MonthlyCOS" for the year so far? I thought I could
have the underlying query sum it up by month -- which is working. Now I just
need to sum the months together to come up with a total? Am I off track with
what I'm trying to do?

Thanks!!

:

Then your query would be expected to return 192 rows, not 5.
You are grouping by EmployeeID and summing the MonthlyCOS field.
What is the underlying query doing? Have you validated it is working
correctly?
--
Dave Hargis, Microsoft Access MVP


:

There are 192 employees -- they each have 5 entries in the underlying query
(qRpt_EmployeeCOS_1) -- 1 entry for each month for January - May. MonthlyCOS
is supposed to be a currency data type -- it's a calculation on the
underlying query. I never specify it as a currency, but the items ini the
calculation are either number or currency data types. MonthlyCOS will never
have a Null value.

Thanks!
Heather

:

How many employees do you have in the table?
What data type is [MonthlyCOS]?

Can [MonthlyCOS] ever have a Null value?
--
Dave Hargis, Microsoft Access MVP


:

I think this should be a simple query to do, but I can't get the sum values
correct. Here's my query:

SELECT qRpt_EmployeeCOS_1.EmployeeID, Sum(qRpt_EmployeeCOS_1.[MonthlyCOS])
AS SumOfMonthlyCOS
FROM qRpt_EmployeeCOS_1
GROUP BY qRpt_EmployeeCOS_1.EmployeeID;

I just want a sum of MonthlyCOS by each employee. When I run the report,
the sums are completely off. Also, when I changed the sum to a count it also
returned the wrong value -- it came back with 14 when it should only have
been 5. Any ideas?

Thanks,
Heather
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top