Tableau BI Scripting for Logical Functions
Conditional evaluations and logical operations within Tableau.
A. IF:
IF [Amount] > 1000 THEN "High" ELSE "Low" END
This example evaluates the condition if the Amount in the Sales table is greater than 1000. If true, it returns "High", and if false, it returns "Low". The result will be stored in the Status column.
B. AND:
IF [Age] >= 18 AND [Income] > 50000 THEN TRUE ELSE FALSE END
This example checks if both the Age and Income columns in the Customer table satisfy specific conditions. It returns TRUE if both conditions are true; otherwise, it returns FALSE. The result will be stored in the IsEligible column.
C. OR:
IF [Category] = "Electronics" OR [Category] = "Clothing" THEN TRUE ELSE FALSE END
This example checks if the Category column in the Sales table matches either "Electronics" or "Clothing". If at least one condition is true, it returns TRUE; otherwise, it returns FALSE. The result will be stored in the HasDiscount column.
D. NOT:
IF NOT [Experience] < 2 THEN TRUE ELSE FALSE END
This example checks if the Experience column in the Applicants table is not less than 2. It reverses the logical value of the condition. If the condition is true, it returns FALSE; if the condition is false, it returns TRUE. The result will be stored in the IsQualified column.
212