function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
DaveStDaveSt 

OpportunityLineItemSchedule sum(revenue) in SOQL Query

Hoping you can explain what I am experiencing when running a SOQL query on the OpportunityLineItemSchedule to sum the revenue for this quarter. I have the following query:

SELECT sum(Revenue) FROM OpportunityLineItemSchedule where OpportunityLineItem.Opportunity.StageName in ('Closed Won','Contract','Pricing','Trial','Contract Signed','Schedule Variation Open','Schedule Variation–Signed') and ScheduleDate =THIS_QUARTER

but when I use the same criteria to run an report via SF I get a different amount. The value is more in the report.

The report type I am running is an Opportunity Schedule report and is based on Schedule Date range being in Current FQ (which is 01/07/2016 to 30/09/2016 ) and filtered on Stage equals ('Closed Won','Contract','Pricing','Trial','Contract Signed','Schedule Variation Open','Schedule Variation–Signed') and is returning the Opportunity Name, Stage and Schedule Amount. and returns the Schedule Amount ( as there is no option for Revenue )
Could you tell me what the relationship is between the Schedule Amount ( that I can get from the report ) and the 'Revenue' ( from the dev guides https://developer.salesforce.com/docs/atlas.en-us.api.meta/api/sforce_api_objects_opportunitylineitemschedule.htm ) that I am referring to in the query? I did see a post https://success.salesforce.com/answers?id=9063A000000ZmsoQAC that mentioned sharing limits - I could see the relevance if the amount in the query was greater but it is the other way around and I am really struggling to reconcile the figures.



When I expand the query out to this...

SELECT OpportunityLineItem.Opportunity.ID, OpportunityLineItem.Opportunity.name, OpportunityLineItem.Opportunity.CloseDate, ScheduleDate, Revenue, CurrencyIsoCode FROM OpportunityLineItemSchedule where OpportunityLineItem.Opportunity.StageName in ('Closed Won','Contract','Pricing','Trial','Contract Signed','Schedule Variation–Open','Schedule Variation–Signed') and ScheduleDate = THIS_QUARTER

export to excel and manually sum the revenue i get a different figure than my original sum(revenue) query. Have I expanded this incorrectly?

The expanded query returns less rows than the report so this would explain the difference - I just don't know how to correct it