# I am trying to create a formula to calculate the number of remaining full months left in the year from the closed date

Example::

If close date is not this year, amount this year = 0

If close date is this year, amount this year = Setup cost + (Monthly amount x number of whole months between the close date and the end of the year)

Eg, if the setup was £10k, monthly amount £2k, and close date 14/7, the calculation would be: £10k + (£2k x 5) = £20k

And when we move into 2015, we need to ensure the calculation works as we move into the next year.

The formula to return the number of whole months remaining in the year is just:

``````12 - MONTH(CloseDate)
``````

and you can use the YEAR function to do the year matching part giving you a multiplier factor field of:

``````IF(YEAR(CloseDate) == YEAR(TODAY()), 12 - MONTH(CloseDate), 0)
``````

(And of course you can incorporate the other values in that one formula or in a further formula field.)

I am not sure what exactly you are looking for ,because you have the answer itself.

But what I understood I am giving you a sample (not code i.e. not working code).

Let me know in case of any queries or correct me If I am wrong

``````    int totalAmount=0;
if(closeddate.Year==DateTime.Now.Year)
{
do{
int reaminingMonth=12-ClosedDate.Month;
totalAmount=totalAmount+SetupCost+(monthly_amount* reaminingMonth);
}
while(DateTime.Now.Year<year_you_want)
}
else
{//do what you want  }
``````