Support » Plugin: Calculated Fields Form » Calculating with if, then

  • Resolved Gazza21

    (@gazza21)


    Hi guys, been trying to work this formula out for a time now without success, and cant find any thing related.

    If I need to work out a morgage repayment, but with many variables.

    Eg. Each year period has its own number, 5 years= 26.63, 10 years= 19.49, 15 years=17.75, 20 years=17.18. (these are based on an interest rate of 20.25%)

    So for example, if a loan of 50 000 at an interst rate of 20.25% to be paid over 20 years, the formula is:
    50 000 + 1000 x 17.18 = 859 per month
    How would this formula look, based on that the 17.18 number changes if the year changes??

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author codepeople

    (@codepeople)

    Hello @gazza21,

    The solution depends of your form’s implementation. For example, if the years were defined as a DropDown (or radio buttons) field (for example the fieldname1), you can enter the numbers as the values of the choices and use the fieldname1 directly in the equation (if it is a percentage, please, remember the division operation: fieldname1/100)

    In a hypothetical case, where the user enter the number of years through a number field, and you want apply:

    17.18% if the number of years is equal or greater than 20 years,
    17.75% if the number of years is between 15 and 19
    19.49% if it is between 10 and 14
    and 26.63% if it is between 5 and 9
    Less than 5 is not allowed

    You should determine the percentage to apply with conditional statements as part of the equation, similar to:

    (function(){
    var percent;
    if(fieldname1 < 5) return 'Invalid Years';
    if(5 <= fieldname1) percent = 26.63;
    if(10 <= fieldname1) percent = 19.49;
    if(15 <= fieldname1) percent = 17.75;
    if(20 <= fieldname1) percent = 17.18;
    
    /* Enter here the mathematical operations using the percent variable */
    })()

    Could you include the link to the webpage where the form is inserted, please?

    Best regards.

    Thread Starter Gazza21

    (@gazza21)

    Thank you so much for the support, I truly appreciate it.

    So sorry, still a bit stuck on this.
    Here is the webpage with the calculate:
    http://jlesliesmith.brandlinx.org/bondrepayment/

    Could you perhaps give me a start of two calculations as per the below, then I can copy and fill in the rest?? not sure of the mathematical operation

    Loan amount (client fills in): fieldname2
    Interest rate (dropdown): fieldname3
    years (dropdown): fieldname1

    Interest 20.25% 5yrs=26.63 10yrs=19.49 15yrs=17.75
    Interest 20.50% 5yrs=26.77 10yrs=19.66 15yrs=17.93

    Plugin Author codepeople

    (@codepeople)

    Hello @gazza21,

    I’m sorry, I cannot implement your project as support service, if you need the implementation of your equations, please, request a custom coding service through my private website:

    https://cff.dwbooster.com/customization

    As support service, I can give you some indications and tips.

    For example, assuming your form includes two dropdown field: fieldanem1 and fieldname2, where fieldname1 includes the choices: A, B and C, and the fieldname2 the choices: 1 and 2, and you want multiply the fieldname3 that is a number field by a factor depending on the choices selected in the other two fields as described below:

    – If A and 1 were selected in the fields fieldname1 and fieldname2 respectively, then, use the factor 0.5
    – If A and 2 – Factor: 0.8
    – If B and 1 – Factor: 0.3
    – If B and 2 – Factor: 1
    – If C and 1 – Factor: 0.9
    – If C and 2 – Factor: 0.7

    Note: The fields’ names, the choices and values are hypothetical, only to describe the process.

    The equation corresponding to this hypothetical case might be:

    
    (function(){
    var factor = 0;
    if(fieldname1 == 'A' && fieldname2 == 1) factor = 0.5;
    if(fieldname1 == 'A' && fieldname2 == 2) factor = 0.8;
    if(fieldname1 == 'B' && fieldname2 == 1) factor = 0.3;
    if(fieldname1 == 'B' && fieldname2 == 2) factor = 1;
    if(fieldname1 == 'C' && fieldname2 == 1) factor = 0.9;
    if(fieldname1 == 'C' && fieldname2 == 2) factor = 0.7;
    return fieldname3*factor;
    })()
    

    Another possibility, creating an object with the combinations, and use the fields’ names as the names of the object’s attributes:

    
    (function(){
    var db = {
    'A':{1:0.5, 2:0.8},
    'B':{1:0.3, 2:1},
    'C':{1:0.9, 2:0.7}
    };
    return fieldname3*db[fieldname1][fieldname2];
    })()
    

    Best regards.

    Thread Starter Gazza21

    (@gazza21)

    Came right!!! Thank You!

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Calculating with if, then’ is closed to new replies.