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
Sandrine94748Sandrine94748 

Algo to distribute a amount equally over 3 years

Hello,

I have a usescase where i need to distribute a amount for period of 3 years.
If example total is 36k and if the start date is in Jan 2016 then the amount is dristributed as 12k for 16,17 & 17.
But if the start date is in Oct 2015 then the amount will be
2015 = 3k
2016 = 12k
2017 = 12k
2018 = 9k

Each of the amounts will be stored in the specific field, how cn i create a algo for it.
thank you for suffestion
GauravGargGauravGarg
Hi Sandrine,

If this is the requirement for Formula field, then lets assume Year value has multiple i.e. 2015_year, 2016_year, 2017_year, 2017_year. All these fields would be formula field and will be automatically calculated based on a particular. 

Let take a scenario for a custom date field : LastCalculateDate__c

So each year field would be a formula field with formula:
total__c * (MONTH(LastCalculateDate__c) / 12)

for Apex:
public class CalculateYearlyTotal
{
	public class CalculateYearlyTotal()
	{
		for(Sobject so : List<Sobject>)
		{
			so.2015_year = total * ((LastCalculateDate__c.month)/ 12);
			so.2016_year = total * ((LastCalculateDate__c.month)/ 12);
			so.2017_year = total * ((LastCalculateDate__c.month)/ 12);
			so.2018_year = total * ((LastCalculateDate__c.month)/ 12);
		}
		update so;
	}
}



Hope this helps !!!

 

Thanks,

Gaurav
Skype: gaurav62990

Sandrine94748Sandrine94748
hello Gaurav, thank you for suggestion.
but the LastCalculateDate__c.month)/ 12 will not give me the exact value i need.
I describe by second scenation in questions
 
GauravGargGauravGarg
Hi,

Please modify the criteria to 
(13 - LastCalculateDate__c.month) / 12

This will provide you correct result