• Resolved artinkprint

    (@artinkprint)


    Hi, I’m trying to set a logical operation to show an answer for 3 different results, have been trying to use IF however this only works for two results.

    Essentially I’m looking for the following
    Fieldname4 less than 1 gives result X
    Fieldname4 greater than 1 but less than 2 results in Y
    Fieldname4 greater than 2 results in Z

    For example
    IF(fieldname4<1, ‘X’, ‘Y’) works for part of the equation
    however I want to add if fieldname>2 the result will be ‘z’

    Any help would be much appreciated!

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

    (@codepeople)

    Hello @artinkprint,

    There are multiple alternatives to implement the equation, using the conditional statements “if” of javascript and function structure, or if you prefer to use the “IF” operation, you simply should nest some of them, as follows:

    – Using the function structure:

    
    (function(){
    if(fieldname4 < 1) return 'X';
    if(1 <= fieldname4 && fieldname4 < 2) return 'Y';
    return 'Z';
    })()
    

    – Using the “IF” operation:

    
    IF(fieldname4 < 1, 'X', IF(AND(1<=fieldname4,fieldname4<2), 'Y', 'Z'))
    

    Best regards.

    Thread Starter artinkprint

    (@artinkprint)

    Amazing! Thank-you for your quick and accurate response @codepeople
    I have one more question…

    I need to get the result to the following function in a format which has two digits after the decimal (for a dollar value). I can’t figure out where to place the PREC(

    (function(){
    if(fieldname4 <= 8) return fieldname4*19;
    if(fieldname4 > 8) return fieldname4*17;
    })();

    Thanks again!!

    Plugin Author codepeople

    (@codepeople)

    Hello @artinkprint,

    You can use the “PREC” operation with every return instruction:

    
    (function(){
    if(fieldname4 <= 8) return PREC(fieldname4*19,2);
    if(fieldname4 > 8) return PREC(fieldname4*17,2);
    })();
    

    But actually, the equation can be implemented in a more optimized way:

    
    PREC(fieldname4*IF(fieldname4 <= 8,19,17),2)
    

    Best regards.

    Thread Starter artinkprint

    (@artinkprint)

    Thank-you so much @codepeople this made my day!

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Calculated field is less than, but greater than.’ is closed to new replies.