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
BabaganoushBabaganoush 

How to generate a monthly revenue breakdown using start end dates on Opportunity object?

The Opportunity object has project start and end dates along with total revenue. Need a way so that user can see a month by month breakdown with revenue divided over each month.
For example if start date is 05/2018 and end date is 07/2018 with revenue of 90,000 USD then one should be able to see three columns one for May, June, and July and with 30,000 in each column as a breakdown for revenue. The user should have ability to enter an override for the revenue for each month.


Is there some built in functionality or revenue forecasting type plugin that would work better?  
NagendraNagendra (Salesforce Developers) 
Hi Scott,


As VisualForce, generically speaking, what you'll need to do is create a custom controller for your "Revenue Report" on Opportunity. The class would be an extension of Opportunity that would also enclose the results in a wrapper. Your controller would begin by getting the start and end dates from your page then run a query that's grouped by each time period you want to use and put the results into a "wrapper class".

You'd then output those results in a table on a VisualForce Page using an <Apex: repeat> tag. The html for the page would look something like this:

May I suggest you please find the sample code below and tweak it as per the requirement which should help you further.
<apex:page standardController="Opportunity" extensions="MYCustomController" standardStylesheets="false">

<apex:stylesheet value="{! URLFOR($Resource.MyCustomStyleSheet.css')}"/>
// add any custom styling here

<table>
  <tr>
  <td>Start Date</td>
  <td>End Date</td>
  <td>Account Name</td>
  <td>Opp Amount</td>
  <apex:repeat> value="{!wrapper}" var="w">
    <apex:repeat value="{!w.OLst}" var="o">
    <tr>
    <td>{!o.StartDate}<td>
    <td>{!o.StartDate}<td>
    <td>{!o.Account.Name}</td>
    <td>{!o.Opportunity.Amount}</td>
    </tr>
    </apex:repeat>
    <tr>
    <td>{!w.StartDate}<td>
    <td>{!w.StartDate}<td>
    <td> </td>
    <td>Grand Total: <apex:outputText value="${0,number,0.00}"><apex:param value="{!w.GT}"/></apex:outputText>
    </tr> 
  </apex:repeat>
</table>
</apex:page>
With the above, you could potentially have multiple start and end dates if chose to, causing the table to get longer with each period rather than wider. This should give you a good starting point. Your query would also want to roll-up any opportunities for the period on each account if you don't want to need to group and sum them (a pita if you do).

Hope this helps.

Kindly mark this as solved if the reply was helpful.

Thanks,
Nagendra


 
Raj VakatiRaj Vakati
You need to use Cutsome code to do this with SOQL and wrapper class to show the data into UI .. 


But You can try to create a report also it may work if you just want to show the data