Tuesday, June 27, 2023

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

In Tableau, the "ELSE" clause is used in conjunction with the "CASE" logical function. It defines the action or result to be taken when none of the specified conditions in the "CASE" function evaluate to true. The "ELSE" clause is optional and provides a default value or fallback action.


Here's an example to illustrate how the "ELSE" clause works in Tableau:


Suppose you have a dataset of students and their scores, and you want to create a calculated field that assigns a grade based on the score. You define specific ranges for each grade (A, B, C, D, and F) and want to assign 'Unknown' for any score that falls outside of these ranges.


CASE WHEN [Score] >= 90 THEN 'A' WHEN [Score] >= 80 THEN 'B' WHEN [Score] >= 70 THEN 'C' WHEN [Score] >= 60 THEN 'D' ELSE 'F' END

In this example, the "CASE" function is used to check multiple conditions and assign grades based on the score. The first condition checks if the score is greater than or equal to 90 and assigns the value 'A'. The subsequent conditions check decreasing score ranges and assign corresponding grades ('B', 'C', 'D').

The "ELSE" clause is used as the last condition and specifies the result to be used when none of the previous conditions evaluate to true. In this case, if the score is below 60, the "ELSE" clause will assign the value 'F'.


For example, if a student has a score of 85, the "CASE" function will evaluate the second condition and assign the value 'B'. If another student has a score of 55, the "ELSE" clause will be triggered since none of the previous conditions apply, and the value 'F' will be assigned.


The "ELSE" clause in the "CASE" function provides a way to handle situations where none of the specified conditions match. It ensures that a default action or value is assigned when there are no matches, helping you handle all possible scenarios in your data analysis or visualization. 

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 ...