If - then calculation via category
Hi,
I'm trying to make a simple calculation where IF a category field is set to "X" THEN return a specific number or text in a calculation field.
Eg. IF "employee status" = type A, THEN show "15%"
or IF "employee status" = type B, THEN show "150"
I tried various combinations of what I could find online here, but nothing that worked so far.
Best, Tue
-
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
-
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)
Please sign in to leave a comment.
Comments
8 comments