Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
ShowAll Questionssorted byDate Posted
lopezc

# Problem with SUM()

Hi,

I am query the data base to get the SUM(Amount__c), the table has 6 records with amounts 100 and 10. How Can it be possible that the SUM gives me 74.0?

Here is the the data saved in the LedgerTransaction__c  table:

[SELECT Amount__c

FROM  LedgerTransaction__c where

and Transaction_Type__c = 'Cash In'

and Ledger_Summary__c = 'a1220000000LPDJAA4'];

Result:

(LedgerTransaction__c:{Id=a0PS0000000zGrMMAU, Amount__c=100.00}, LedgerTransaction__c:{Id=a0PS0000000zJ49MAE, Amount__c=10.00}, LedgerTransaction__c:{Id=a0PS0000000zJ4EMAU, Amount__c=10.00}, LedgerTransaction__c:{Id=a0PS0000000zJ4OMAU, Amount__c=10.00}, LedgerTransaction__c:{Id=a0PS0000000zJ4TMAU, Amount__c=10.00}, LedgerTransaction__c:{Id=a0PS0000000zJ7cMAE, Amount__c=10.00})

AggregateResult[] ec= [SELECT SUM(Amount__c),COUNT(Id) FROM  LedgerTransaction__c where Amount__c > 0
and Transaction_Type__c = 'Cash In'
and Days_Since_Transaction__c <= 60
and Ledger_Summary__c = 'a1220000000LPDJAA4'
GROUP BY Ledger_Summary__c];
System.debug(ec);

[SELECT SUM(Amount__c),COUNT(Id)

FROM  LedgerTransaction__c

and Transaction_Type__c = 'Cash In'

and Ledger_Summary__c = 'a1220000000LPDJAA4'

GROUP BY Ledger_Summary__c];

Result: (AggregateResult:{expr0=74.0, expr1=6})

Any Ideas?

lopezc

I know why :)

The Amount is in different currencies