Seemingly incorrect sum of records when grouped. What's happening?

colewillm

New Member
Joined
Oct 8, 2014
Messages
6
Hello,

I'm having a problem that is throughout my database, but I will limit it to one example in this post. I'm running a query on records with ID '100' which returns two pieces of data both with EARNED_PREMIUM_USD ($360.01). Logically you could expect the sum of these to be ($720.02), but on the aggregate sum query it returns ($923.23). What is going on here?

I will post the SQL code for the two queries below.
SELECT dbo_XLOAD_PREMIUM_DATABASE_FC_FINAL_CMP.EARNED_PREMIUM_USD​
FROM dbo_XLOAD_PREMIUM_DATABASE_FC_FINAL_CMP​
WHERE (((dbo_XLOAD_PREMIUM_DATABASE_FC_FINAL_CMP.ID)=100));

SELECT Sum(dbo_XLOAD_PREMIUM_DATABASE_FC_FINAL_CMP.EARNED_PREMIUM_USD) AS SumOfEARNED_PREMIUM_USD
FROM dbo_XLOAD_PREMIUM_DATABASE_FC_FINAL_CMP
WHERE (((dbo_XLOAD_PREMIUM_DATABASE_FC_FINAL_CMP.ID)=100));





 

Excel Facts

Copy a format multiple times
Select a formatted range. Double-click the Format Painter (left side of Home tab). You can paste formatting multiple times. Esc to stop
It is very hard to figure out what may be going on without seeing the data.
Are there any duplicates in your data?
Do you have any NULL values in the ID field?

Does this make any difference?

SELECT Sum(dbo_XLOAD_PREMIUM_DATABASE_FC_FINAL_CMP.EARNED_PREMIUM_USD) AS SumOfEARNED_PREMIUM_USD
FROM dbo_XLOAD_PREMIUM_DATABASE_FC_FINAL_CMP
WHERE dbo_XLOAD_PREMIUM_DATABASE_FC_FINAL_CMP.ID=100
GROUP BY dbo_XLOAD_PREMIUM_DATABASE_FC_FINAL_CMP.ID;
 
Last edited:
Upvote 0
Just for kicks, post exactly the results of these two queries:
Code:
SELECT 
	dbo_XLOAD_PREMIUM_DATABASE_FC_FINAL_CMP.EARNED_PREMIUM_USD
FROM 
	dbo_XLOAD_PREMIUM_DATABASE_FC_FINAL_CMP
WHERE 
	dbo_XLOAD_PREMIUM_DATABASE_FC_FINAL_CMP.ID = 100;
	
SELECT 
	Sum(dbo_XLOAD_PREMIUM_DATABASE_FC_FINAL_CMP.EARNED_PREMIUM_USD) AS SumOfEARNED_PREMIUM_USD
FROM 
	dbo_XLOAD_PREMIUM_DATABASE_FC_FINAL_CMP
WHERE 
	dbo_XLOAD_PREMIUM_DATABASE_FC_FINAL_CMP.ID = 100;
 
Upvote 0

Forum statistics

Threads
1,215,003
Messages
6,122,655
Members
449,091
Latest member
peppernaut

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top