Skip to main content
2 of 2
added 12 characters in body

SOQL SUM() function not calculating the correct value

I have a SOQL query that I'm trying to use the SUM function with. My issue is that the SUM function gives me a totally different result than if i just query the rows and add up the amounts

Query 1 - Selecting the rows individually

select id,  Parts_Cost__c from customObject where Status= 'Completed' 
and Contract = :contractId and Completed_On__c >= :contractStartDate  
and Completed_On__c <= :contractEndDate

The individual results for parts cost sum to- 6773.59 and 17 rows are returned

Query 2- Aggregate Results:

select count(id),  sum(Parts_Cost__c) from customObject where Status= 'Completed'
and Contract = :contractId and Completed_On__c >= :contractStartDate  
and Completed_On__c <= :contractEndDate

This will give me a summed value of 8036.05 and the count result is 17 rows.

Can anyone think of reasons for these discrepancies in the results? Can I see how the 8036.05 is getting calculated?

denisoleary
  • 347
  • 1
  • 4
  • 16