Newbies MetDick Posted September 8, 2012 Newbies Posted September 8, 2012 I need to calculate a commission value from a currency field called "amount". Over the first 2500 the commission is 15% with a minimum of 40. Over the next 2500 the commission is 10% Over the next 5000 the commission is 5% Over the next 190000 the commission is 1% Over the remaining amount the commission is 0,5 % with a maximum of 6775. I am stuck Help is rewarded with a LinkedIn endorsement or enternal friendship! Dick
comment Posted September 8, 2012 Posted September 8, 2012 The calculation itself could be fairly simple - see a somewhat similar example here: http://fmforums.com/...lf/#entry394693 However, I would worry about hardcoding the ranges and the associated rates and extrema, as these are inevitably bound to change. What's worse, even the number of ranges could change - so this would suggest either auto-entering the result of a custom recursive function, or using a looping script to write it out. 1
David Jondreau Posted September 8, 2012 Posted September 8, 2012 Why do you recommend a recursive CF or looping script rather than just a regular custom function?
comment Posted September 8, 2012 Posted September 8, 2012 As I said, the number of ranges could change. I believe you need to calculate the sub-commission for each range. I don't see how you could do that without recursing/iterating/looping.
jbante Posted September 9, 2012 Posted September 9, 2012 Could you clarify the formula for us a bit? If the amount is $6000, should the commission be: 6000 * .05 = 300 ... or: 2500 * .15 + ( 5000 - 2500 ) * .1 + ( 6000 - 5000 ) * .05 = 675
comment Posted September 9, 2012 Posted September 9, 2012 I'll let OP answer that, but note that: 2500 * 15% > 2501 * 10% so that the first option is rather absurd. 1
jbante Posted September 9, 2012 Posted September 9, 2012 Touche, comment. MetDick, I welcome LinkedIn endorsements, and this seemed like a fun exercise, so I made a quick demo file of the second calculation method with both script and custom function formats. Commission.zip
dansmith65 Posted September 9, 2012 Posted September 9, 2012 I loaded this post last night when post #5 was the most recent, then forgot to refresh it when I read it this morning, so hadn't seen the last two posts before I wrote this calc... Max( Min( 2500 ; amount ) * .15 ; 40 ) + Max( Min( 2500 ; amount - 2500 ) ; 0 ) * .1 + Max( Min( 5000 ; amount - 2500 - 2500 ) ; 0 ) * .05 + Max( Min( 190000 ; amount - 2500 - 2500 - 5000 ) ; 0 ) * .01 + Min( Max( amount - 2500 - 2500 - 5000 - 190000 ; 0 ) * .005 ; 6775 ) MetDick, you'll find there are many ways do accomplish a task in FileMaker. Comparing my calc to Jeremy Bante's: his is much easier to edit, but mine creates fewer dependencies (easier to add to your database).
jbante Posted September 9, 2012 Posted September 9, 2012 What dependencies are you referring to, Dan? The custom function and the script versions of the calculation I made don't reference any other functions or scripts that aren't built-in to FileMaker, which makes them dependency-free by my reckoning. I even refrained from using my preferred custom functions for name-value pair script parameters to keep them that way. Copy-and-paste either the script or the custom function into a different file, and they just work. Is there a different idea of what code dependencies are that I'm missing? The file I posted does include some extra fields to store the different parameters of the commission calculation and a script to set the calculated values to display fields, but only for the sake of demonstration. The script and the function are both dependent on being supplied those parameters to function correctly, which I suppose is a dependency of sorts, but not what I normally think of when I talk about code dependencies. The parameters can come from any source MetDick wants; he doesn't have to use the same global repeating fields to specify the commission brackets or the same looping script to set the calculated values into fields. MetDick could just as easily use string literals for parameters: CommissionBracketed ( amount; "2500¶5000¶10000¶200000"; ".15¶.1¶.05¶.01¶.005"; 40; 6775 )
dansmith65 Posted September 9, 2012 Posted September 9, 2012 Jeremy, I only glanced at your attached file so I hadn't realized the fields were only used to hold the values that get passed to the script or the custom function. The dependencies I was referring to were the fields, and as you pointed out, those aren't actually required, so I was wrong about that. In that case, the custom function you wrote seems ideal - it's much easier to modify the rates/cut-off points than my calculation.
Recommended Posts
This topic is 4527 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