If - then calculation via category

Comments

8 comments

  • Rainer Grabowski

    Hi Tue,

    @employee status == "type A" ? "15%" : @employee status == "type B" ? "150" : 0

    Rainer

    2
    Comment actions Permalink
  • Tue Roth

    Hi Rainer, 

    Thanks a lot - it worked like a charm :)

    0
    Comment actions Permalink
  • Reece Carter

    @RAINER similar to this calc, how can get a result for BOTH categories to give a result?

     

    Eg. IF "employee status" = type A & type B, THEN show "165%"

     

    0
    Comment actions Permalink
  • Rainer Grabowski

    Hi Reece,

    is @employe status a multi choice category field or a single choice? If single choice it's if Type A OR Type B. If multiple choice both (OR and AND) are possible

    For single choice: 

    var es = @employe status;
    es == "TypeA" || es = "Type B" ? "165%" : ""


    For multiple choice AND (= both have to be selected): 

    var es = @employe status.join();
    es.indexOf("TypeA") > -1  &&  es.indexOf("TypeB") > -1 ? "165%" : ""

    For multiple choice OR (= either Type A or Type B have to be selected): 

    var es = @employe status.join();
    es.indexOf("TypeA") > -1  ||  es.indexOf("TypeB") > -1 ? "165%" : ""

    But be aware that "165%" is a text string, which is hard to use for further calculations (e.g. for sums).

    Rainer

    0
    Comment actions Permalink
  • Dan Stroehlein

    How do you use this but return a text string that is a reference from the app?

     

    0
    Comment actions Permalink
  • Rainer Grabowski

    Hi Dan, sorry, I don't understand what you mean. What exactly do you want to do? Getting a string from a text field in a related app?

    Rainer

    0
    Comment actions Permalink
  • Dan Stroehlein

    Hi Rainer,

     

    I actually figured it out instead of putting "100%" I wanted to display a specific app reference so I did (@Schedule) and it worked!  This thread helped a lot, thanks!

    0
    Comment actions Permalink
  • Ashley

    I have a similar question. How would the calculation go for:

     

    IF "employee status" = type A or type B, THEN show "Red"

    or IF "employee status" = type C or type D, THEN show "Blue"

     

    EDIT:

    I got it.

    Using a nested calculation with brackets.

    @employee status == "type A" || @employee status == "type B" ? "Red" : (@employee status == "type C" || @employee status == "type D" ? "Blue" : 0)

    0
    Comment actions Permalink

Please sign in to leave a comment.

Powered by Zendesk