AnsweredAssumed Answered

Help with Calculation Field

Question asked by skashanchi on Sep 21, 2015
Latest reply on Sep 21, 2015 by erolst

I am asking for some general and some specific help with a calculation field I am trying to set up. The field is called CalculatedFare and it calculates the taxi fare for a trip based on several criteria. These criteria are set by other fields on the layout. Some of these fields are checkboxes and others are values entered.

 

The criteria involved in calculating the fare are as follows:

 

The general calculation is Static Pickup Fee + (Distance x Rate) + Surcharges - Discounts

 

But several factors affect the rate and the amount of the surcharge

 

Distance = number of miles entered by the user

Rate = $1.50/mile if distance is =< 100 miles, $2.50/mile if distance > 100 miles

Airport (Checkbox) = If pickup location is Airport, apply a 10% surcharge of the whole trip

Multi-Load (Checkbox) = If checked, apply a 20% to the whole trip amount BEFORE the Airport surcharge

Extra Passengers = Charge $2.00/person for additional passengers

Wait Times: If Wait time is over 5 minutes, charge $1.00/min for wait time

 

etc. ...

 

So I want the CalculatedFare field to dynamically change as the user enters the trip info.

 

So my first question is the general one:

1. What is the best approach to this in terms of programming? Do I build this calculation in the actual field? Or do I put this is a layout script? Or another method altogether

 

2. It looks like I would have to use a lot of If statements to determine the status of the various checkboxes. I am trying to understand the differences between using nested If/Else, vs. If (test, resultone, resulttwo), vs. Case

 

Instead of writing one big formula where each portion is a If () or Case() argument, my instinct is to use local variables and set these variables based on the above criteria and then build the actual calculation using these variables so that the formula is easier to read and modify:

So for example:

 

$pickupfee = $4.50

If(Distance=<100,$rate=1.50,$rate=2.50)

If(Multiload="Yes",$multiload=0.8,$multiload=1)

If(Airport = "Yes"; $airport = 0.1, $airport = 0)

If(ExtraPassengers > 0; $extrapassenger = ExtraPssengers *2; $extpassenger = 0)

 

 

So that would allow me to build the final formula as something like this:

 

= (((Distance * $rate) + $pickupfee + $extpassenger) * $airport ) * $multiload)

 

So what if any comments do you have regarding this approach and where this calculation should take place? And also what is the actual correct syntax for this within the calculation field?

 

Do I write it like this:

 

If ()

AND

If ()

AND

If ()

AND

= formula

 

Thank you.

Outcomes