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
PugPug 

Financial functions (NPV, PMT...) in salesforce

I'm trying to solve calculating NPV from values in a custom object.  Can someone tell how to go about do this before I begin programming it manually?

werewolfwerewolf
Those functions are not presently in the formula language, so you'll have to do it yourself.  I'd recommend doing it in an Apex trigger rather than trying to cobble it together with other formula functions.
PugPug

Since I'm rather new to Force.com and Java (background is .Net), here is how I plan on implementing this:

 

1. Create an Apex utility class that would contain methods for calculating financial functions like NPV

2. Create an Apex trigger to update a custom field with the result of the calculation

 

Seems strange that SalesForce would not include these standard functions in their formula library.  I guess sales people are using tools outside of SF to determine the value of deals.

 

 

 

PugPug
Well I got it to work by manually calculating NPV using a custom class and trigger.  I will post the code once it's cleaned up.
zubinzubin

 

Hi

 

Was wondering if you have the code for NPV.

 

Thank you

Zubin

zubinzubin

 

Was wondering if you have the code for NPV.

pradeeptiwaripradeeptiwari

Hi,

 

can you please share code for NPV. I am also trying to implement it and facing issue with it.

Appreciate your help for this.

 

Thanks,

Pradeep

Skot NelsonSkot Nelson

I acutally just implemeted this as a standard formula field. Of course the exact solution for you will depend on the information you've captured in the opportunity.

 

There is one MAJOR limitattion to this solution: it does not work for an unlimited time period.

 

In my case I have the number of Years on an opportunity. Basically I use a series of if statements that return either the NPV for a given year or a 0 depending on the number of years that has been entered.

 

The end result is a formula that looks like this:

 

Net Present Value = NONDISCOUNTED AMOUNTS

+ IF( DURATION > 1, (Annual Amount) / Interest),0)

+ IF( DURATION > 2, (Annual Amount) / Interest  ^ 2),0)

+ IF( DURATION > 3, (Annual Amount) / Interest  ^ 3),0)

 etc.

 

I've validated my results against Excel's NPV function as well as hand calculations based on this:

http://www.financeformulas.net/Net_Present_Value.html

 

Keep in mind the tiem period limitation. In my example above a fourth year would not be calculated. This may not meet your requirements. Doing NPV properly with support for any time period requires a loop, and formulas can't loop. This is a decent accurate hack for me until I upgrade editions.