EDUCBA

EDUCBA

MENUMENU
  • Free Tutorials
  • Free Courses
  • Certification Courses
  • 360+ Courses All in One Bundle
  • Login

Case Statement in Tableau

By Priya PedamkarPriya Pedamkar

Home » Data Science » Data Science Tutorials » Tableau Tutorial » Case Statement in Tableau

Case Statement in Tableau

Introduction to Case Statement in Tableau

The CASE statement or CASE function in Tableau is a part of logical functions. It is similar to the IF statement in a way that it goes on checking the condition one by one. However, the difference between the two lies in the fact that a CASE statement considers conditions as cases and hence the name. The central element to the CASE function is the expression which the function needs to evaluate. Further, the function compares the expression to a sequence of values one by one. When the expression matches any value then the corresponding value is returned as the result.

Using CASE statement – A step-by-step approach

The syntax of the CASE statement in Tableau is as shown below.

Start Your Free Data Science Course

Hadoop, Data Science, Statistics & others

CASE
<expression>
WHEN <value 1> THEN <return result 1>
WHEN <value 2> THEN <return result 2>
WHEN <value 3> THEN <return result 3>
ELSE <default return>
END

The above syntax is the standard one and here default return means a value that should be returned if no match is found. Remember, suitable values should be returned, based on the context, in case of no match.

Illustration

We will now demonstrate the use of the CASE function through an illustration. The dataset contains distribution volume by distribution units. Here, the important dimensions are Region and Distribution unit and Distribution Volume is a measure. Our goal is to categorize distribution units based on distribution volume. To facilitate our analysis, we will create a single field that combines region and distribution unit names. Let’s proceed with the steps.

1. Load the data into Tableau. For that click on “New Data Source” in the Data menu or alternatively click on “Connect to Data”.

Case Statement in Tableau

2. In “Connect”, select the requisite data source type. In this case, the data source type is Microsoft Excel.

Case Statement in Tableau

3. The data gets loaded and can be viewed in the “Data Source” tab as shown below.

Case Statement in Tableau

4. Moving to the sheet tab, we can find the dimensions and the measure in the dataset present in the respective sections.

Case Statement in Tableau

5. To begin with, just drag dimensions Region and Distribution Units into Rows region and measure Distribution Volume into the Columns region. We get a horizontal bar chart as can be seen in the following screenshot. If the default chart type is not a bar chart, then select it from Show Me. The next steps will create a combined field using the CASE statement which will combine the region and distribution unit names.

create calculated field

6. To create a combined field right-click anywhere in the blank space in the Data section and click on the option “Create Calculated Field…” as shown below.

Popular Course in this category
Tableau Training (4 Courses, 6+ Projects)4 Online Courses | 6 Hands-on Projects | 39+ Hours | Verifiable Certificate of Completion | Lifetime Access
4.5 (6,121 ratings)
Course Price

View Course

Related Courses
Business Intelligence Training (12 Courses, 6+ Projects)Data Visualization Training (15 Courses, 5+ Projects)

case statement.6

7. The calculated field that we created looks as shown in the below screenshot. As can be seen, the combined field has been created using the CASE function. Here, the expression used is dimension Region. Based on the region name, the combined field will be created by combining the first three letters from the name of the region with the first three letters of the distribution unit name. In order to extract the first three letters from the distribution unit, we used the LEFT function. Not all the letters of distribution unit are in the upper case, so in order to convert them to an upper case, we passed the result to the UPPER function. The CASE function thus offered us a systematic approach to create a combined field.

distribution volume analysis

8. The newly created field REG_DU can be seen in the Dimensions section as below.

case statement.8

9. Now, just drag the newly created field REG_DU into rows region and distribution volume into columns region as shown below.

reg UV

10. Let’s have a closer look at the visualization. We can see the names from region and distribution units combined. This will help in quick analysis and easy insight capturing. However, the analysis is incomplete until we categorize the distribution units based on distribution volume. To achieve the objective, we will follow the steps as illustrated by the screenshots subsequent to the below one.

create parameter

  1. We will create two parameters representing average volume and high volume. The average volume for all the distribution units is 30000 and we are considering high volume as 90000. To create a parameter, right-click anywhere in the blank space in the Data section and click on “Create Parameter…”.

case statement.11

12. Create the parameters with appropriate names and mentioned values as shown by the following two screenshots.

Case Statement in Tableau

two parameters

13. The two parameters can be seen in the “Parameters” section below.

case statement.13

14. Next, create a calculated field for classification. We have named it VOL_CLASS. Going through the code in the field, it can be seen that distribution units having a volume over or equal to 90000 have been classified as “Very High Volume DU”, those with the volume between 30000 and 90000 are “Average Volume DU”, and rest is “Below Average” DUs.

created field

15. The newly created field can be seen in the measures section as can be seen in the below screenshot. Remember, this field uses measure Distribution Volume and so automatically gets categorized as a measure.

case statement.15

16. Now, drag the field REG_DU in the Rows region and measure Distribution Volume in the Columns region. Further drag field VOL_CLASS over Color in Marks card. We get the following visualization, where we can see the Distribution Units classified in different volume categories.

dimension measured

17. The following screenshot offers a closer look into the analysis. Here we have arranged the legend in proper order as against what it was in the preceding screenshot. Also, appropriate colors have been assigned to the categories, with results arranged in descending order.

case statement.17

18. While analyzing distribution unit volume contribution, the above chart gives good insight. However, a bubble chart is more insightful in such an analysis. So, next, sort the result in alphabetical order of the REG_DU names and click over “packed bubbles” in Show Me as can be seen below.

reg DU

19. As can be seen below, we get a bubble chart that proves to be the right tool for our task as it represents the categories through color and size combinations.

case statement.19

Conclusion

Tableau being a typical visual analytics tool, it employs every feature to come up with interactive and insightful analysis through visualizations. The CASE function in Tableau is employed to deal with conditional situations the result obtained from which is utilized based on the context and it affects the visual output.

Recommended Articles

This is a guide to the Case Statement in Tableau. Here we discuss the introduction and step by step approach using Case statement in Tableau along with Illustration. You can also go through our other suggested articles to learn more –

  1. Tableau Visualization
  2. Rank Function in Tableau
  3. What is Tableau?
  4. Pivot in Tableau
  5. Tableau Context Filter
  6. Tableau Bullet Chart

Tableau Training (4 Courses, 6+ Projects)

4 Online Courses

6 Hands-on Projects

39+ Hours

Verifiable Certificate of Completion

Lifetime Access

Learn More

0 Shares
Share
Tweet
Share
Primary Sidebar
Tableau Tutorial
  • Statement
    • Tableau IF Statement
    • Case Statement in Tableau
  • Basic
    • What is Tableau
    • What is Tableau Dashboard
    • What is Tableau Server
    • Uses of Tableau
    • Tableau Versions
    • Tableau Architecture
    • Is Tableau Free
    • Tableau New Features
    • How To Install Tableau
    • How to Use Tableau?
    • Install Tableau Server
    • Tableau Commands
  • Charts
    • Tableau Charts
    • Tableau Chart Types
    • Donut Chart in Tableau
    • Funnel Chart in Tableau
    • Gantt Chart in Tableau
    • Bubble Chart in Tableau
    • Pareto Chart in Tableau
    • Sankey Chart In Tableau
    • Stacked Bar Chart in Tableau
    • Tableau Bullet Chart
    • Waterfall Chart in Tableau
    • Line Chart in Tableau
    • Heat Map in Tableau
    • Histogram in Tableau
    • CrossTab in Tableau
    • Treemap in Tableau
    • Trend Lines in Tableau
    • Tableau Reference Lines
    • Tableau Dual Axis
    • Legend in Tableau
    • Pie Chart in Tableau
    • Tableau Storyline
  • Functions
    • Tableau Functions
    • Tableau String Functions
    • Concatenate in Tableau
    • Rank Function in Tableau
    • Tableau Aggregate Functions
    • Tableau Date Functions
    • Window Sum Tableau
    • LOD Expressions in Tableau
    • LOOKUP Function in Tableau
    • Tableau Fixed Function
    • Tableau Count Distinct
    • Tableau Window Functions
  • Sort/Filters
    • Sorting in Tableau
    • Filters in Tableau
    • Types of Filters in Tableau
    • Tableau Action Filter
    • Context Filter in Tableau
    • Tableau Parameter Filter
    • Adding Filters in Tableau Dashboard
    • Tableau Context Filter
  • Tableau Dashboard
    • Dashboard in Tableau
    • Tableau Dashboard Creation
    • Tableau Dashboard Design
    • Tableau Workbook
  • Advanced
    • Tableau Reporting
    • Tableau Reporting Tool
    • Conditional Formatting in Tableau
    • Data Blending in Tableau
    • Parameters in Tableau
    • Tableau Data Sets
    • Tableau Drill Down
    • Tableau Dynamic Parameters
    • Tableau Table Calculation
    • Tableau Visualization
    • Tableau Joins
    • Pivot in Tableau
    • Data Visualization With Tableau
    • Forecast in Tableau
    • Map Layers in Tableau
    • Group in Tableau
    • Tableau Group by
    • Hierarchy in Tableau
    • Sets in Tableau
    • How to create a Set in Tableau
    • Tableau Order of Operations
    • Tableau User Group
    • Tableau Calculated Field
    • Custom SQL in Tableau
  • Interview Questions
    • Tableau Interview Questions

Related Courses

Tableau Certification Course

Business Intelligence Courses

Data Visualization Courses

Footer
About Us
  • Blog
  • Who is EDUCBA?
  • Sign Up
  • Corporate Training
  • Certificate from Top Institutions
  • Contact Us
  • Verifiable Certificate
  • Reviews
  • Terms and Conditions
  • Privacy Policy
  •  
Apps
  • iPhone & iPad
  • Android
Resources
  • Free Courses
  • Database Management
  • Machine Learning
  • All Tutorials
Certification Courses
  • All Courses
  • Data Science Course - All in One Bundle
  • Machine Learning Course
  • Hadoop Certification Training
  • Cloud Computing Training Course
  • R Programming Course
  • AWS Training Course
  • SAS Training Course

© 2020 - EDUCBA. ALL RIGHTS RESERVED. THE CERTIFICATION NAMES ARE THE TRADEMARKS OF THEIR RESPECTIVE OWNERS.

EDUCBA Login

Forgot Password?

EDUCBA
Free Data Science Course

Hadoop, Data Science, Statistics & others

*Please provide your correct email id. Login details for this Free course will be emailed to you
Book Your One Instructor : One Learner Free Class

Let’s Get Started

This website or its third-party tools use cookies, which are necessary to its functioning and required to achieve the purposes illustrated in the cookie policy. By closing this banner, scrolling this page, clicking a link or continuing to browse otherwise, you agree to our Privacy Policy

EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you
EDUCBA
Free Data Science Course

Hadoop, Data Science, Statistics & others

*Please provide your correct email id. Login details for this Free course will be emailed to you

Special Offer - Tableau Training (4 Courses, 6+ Projects) Learn More