Newbies strudleman Posted November 30, 2012 Newbies Posted November 30, 2012 **Disclaimer** I've been around scripting and databases for years(PHP, Perl, Oracle, MySQL, etc) but I've been working with FM Pro Advanced 12 for just a few days now. I apologize for what I'm sure will turn out to be the dumbest question of the year. I have a piece of equipment which costs '$cost' I have an equipment lifespan which is '$years' I have a static cost inflation rate which is 2.5% I have a field which is supposed to estimate the cost of replacing this item at the end if it's lifespan, and that value needs to be automagically populated. This pseudo code will hopefully explain what I'm trying to do: $cost = cost; $years = years; while ($years != 0){ $years - 1; $cost = $cost * 1.025 //That adds 2.5% to the cost }; This function just adds 2.5% to the cost of replacement for this item. Every year, it adds another 2.5% to the previous years cost. My question is.. where do I put it? In the calculation field? A custom function or a script? (I will have to use this on multiple tables) And once I know where to put it, what's the syntax for it going to look like? Thanks everyone. This is my first post here on this forum, but with any luck I'll be around a while. I'm really enjoying the FM experience so for
Ocean West Posted November 30, 2012 Posted November 30, 2012 A custom function would be the place for this, this is a recursive function EquipValue ( cost ; lifespan ) Let ( [ inflation = cost * 1.025 // adds fixed 2.5% to cost ]; Case ( lifespan = 0 ; inflation + EquipValue ( cost ; lifespan - 1 ) )) Does the inflation rate ever change? If so you could add that as a parameter and then in the calculation or script where this is referenced you can provide that value. EquipValue ( cost ; lifespan ; rate ) replace the 1.025 in the formula above with the rate. inflation = cost * rate // rate value provided by script or runtime calculation if this function is used in calculation and the you change the rate here it would affect ALL instances in all tables where this is used. you may want to add this to an auto enter calculation and allow it to change if the other reference fields are changed - so that if you do change the rate it would not affect historical records. ( unless that is acceptable to your solution business logic ) hope this helps, and welcome to the forums! stephen
comment Posted November 30, 2012 Posted November 30, 2012 How about some simple math? Cost * ( 1 + Rate )^Years My question is.. where do I put it? In the calculation field? A custom function or a script? (I will have to use this on multiple tables) You would put this inside the definition of a calculation field. I don't see why you would have to use this in multiple tables - sounds like you need to re-examine your data structure. 1
Newbies strudleman Posted November 30, 2012 Author Newbies Posted November 30, 2012 Ocean West, thanks for the detailed reply and comments. That's exactly what I was looking for! But I can't deny the elegant simplicity in Comments solution. That's just fantastic.
Recommended Posts
This topic is 4433 days old. Please don't post here. Open a new topic instead.
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now