Tuesday, June 27, 2023

Explain the Logical Function ' END' in Tableau with Example?

 In Tableau, the "END" keyword is used to mark the end of a logical expression or statement. It is typically used in conjunction with other logical functions, such as "IF" or "CASE," to indicate the completion of the expression.


Here's an example to illustrate the use of "END" in Tableau:


Suppose you have a dataset of products and their prices, and you want to create a calculated field that applies a discount based on the product type. If the product is of type "Electronics," you want to apply a 10% discount. For other product types, no discount should be applied.


IF [Product Type] = 'Electronics' THEN [Price] * 0.9
ELSE [Price]
END

In this example, the "END" keyword is used to mark the completion of the "IF" statement. The "IF" function checks whether the product type is 'Electronics'. If the condition is true, it applies a 10% discount by multiplying the price by 0.9. If the condition is false (i.e., the product is not of type 'Electronics'), the original price is returned.


The "END" keyword ensures that the "IF" statement is properly closed and the result of the calculation is returned. Without the "END" keyword, Tableau would generate an error due to the incomplete logical expression.


You can also find the "END" keyword used in conjunction with the "CASE" function. The "CASE" function allows you to define multiple conditions and corresponding actions. The "END" keyword is used to indicate the end of the "CASE" statement, ensuring that the result is returned after evaluating all conditions.


For example:


CASE
    WHEN [Category] = 'Electronics' THEN 'High'
    WHEN [Category] = 'Clothing' THEN 'Medium'
    ELSE 'Low'
END

In this example, the "END" keyword marks the completion of the "CASE" statement. After evaluating all the conditions, the corresponding result is returned based on the matching condition.


The "END" keyword is essential in Tableau to properly close logical expressions, such as "IF" or "CASE," and indicate the completion of the logic flow. It ensures that the expected result is returned and avoids syntax errors.

No comments:

Post a Comment

If you have any doubts. Please let me know

How can you create an alias for a table in a SQL query?

In SQL, you can create an alias for a table in a query to give the table a temporary, alternative name that you can use in the query. Table ...