• Resolved soenke22

    (@soenke22)


    Dear codepeople,

    my equation in calculation Field 8 is:

    (function(){

    if(fieldname2 < 520 ) return 100+((fieldname2-100)*0.2);

    if(fieldname2 >= 520 ) return 184+((fieldname2-520)*0.3);

    if(fieldname2 >= 1000 ) return 328+((fieldname2-1000)*0.1);

    if(fieldname2 >= 1200 ) return 348);

    })();

    Everything works with the first and second statements – What do I have to do to fulfill conditions 3 and 4?

    Thanks for help!

    The page I need help with: [log in to see the link]

Viewing 1 replies (of 1 total)
  • Plugin Author codepeople

    (@codepeople)

    Hello @soenke22

    Thank you very much for using our plugin.

    The “return” instructions stop the equation execution and return its result. In your equation, the first and second conditional statements cover all variants. If a number is over 1000, it is greater than 520. So, the second conditional statement is satisfied, and your equation returns184+((fieldname2-520)*0.3)

    For this reason the order of the conditional statements in the equation matter. You must include the conditional statements from more specific to general. So, the equation would be:

    
    (function(){
    
    if(1200 <= fieldname2) return 348;
    if(1000 <= fieldname2) return 328+(fieldname2-1000)*0.1;
    if(520 <= fieldname2) return 184+(fieldname2-520)*0.3;
    
    return 100+(fieldname2-100)*0.2;
    
    })();

    Best regards.

    • This reply was modified 8 months, 4 weeks ago by codepeople.
Viewing 1 replies (of 1 total)
  • The topic ‘4 if conditions in calculated fields’ is closed to new replies.