How to use the IF statement in tableau

This recipe helps you use the IF statement in tableau

Recipe Objective:-How to use the IF statement in tableau?

Step 1:-

Import any data set in the data source. For example, here, the "Global Superstore" data set excel file is imported.

Step 2:-

Drag and drop the orders sheet in the schema pane.

Step 3:-

Go to sheet1; here, different dimensions and measures are available. Here we have used the IF statement in tableau. We will replace the Country name "The United States" with "USA" and "The United Kingdom" with "UK" with the help of the IF statement.

Learn How to use XLNet for Text Classification

Step 4:-

Go to the Country dimension and click on the drop-down available. Then click on the create-calculated field, a window will appear named Calculation1, by default. We can rename it as per our requirement. Here the default name Calculation1 is kept as it is.

Step 5:-

Go to the window below where [Country] is shown by default. Type IF in front of [Country]; we can use the tab button so that the IF statement appears.

Step 6:-

Then type the statement as:- IF [Country]="The United States" THEN "USA" ELSEIF [Country]="The United Kingdom" THEN "UK" ELSE "World" END. Click on Apply and Ok.

Step 7:-

Here as per the IF statement typed, we will replace "The United States" with "USA" and "The United Kingdom" with "UK" and the rest of the countries will be under "World".

Step 8:-

A new field Calculation1 will be created under the dimensions, now drag and drop the Calculation1 dimension and Country dimension in the row shelf. Then double-click on sales measure (sum of sales) to appear on the text label under the marks card.

Step 9:-

Now It will create a table, and we can observe that Calculation1 has the USA, UK, and World as per the IF statement, and the Country will have the name as The United States, The United Kingdom. At the same time, the rest of the countries will appear in the world. Here the sales measure (sum of sales) is taken on a text label and will appear in the table as per the statement.

What Users are saying..

profile image

Ed Godalle

Director Data Analytics at EY / EY Tech
linkedin profile url

I am the Director of Data Analytics with over 10+ years of IT experience. I have a background in SQL, Python, and Big Data working with Accenture, IBM, and Infosys. I am looking to enhance my skills... Read More

Relevant Projects

MLOps AWS Project on Topic Modeling using Gunicorn Flask
In this project we will see the end-to-end machine learning development process to design, build and manage reproducible, testable, and evolvable machine learning models by using AWS

Image Classification Model using Transfer Learning in PyTorch
In this PyTorch Project, you will build an image classification model in PyTorch using the ResNet pre-trained model.

Census Income Data Set Project-Predict Adult Census Income
Use the Adult Income dataset to predict whether income exceeds 50K yr based oncensus data.

Time Series Project to Build a Multiple Linear Regression Model
Learn to build a Multiple linear regression model in Python on Time Series Data

Build an optimal End-to-End MLOps Pipeline and Deploy on GCP
Learn how to build and deploy an end-to-end optimal MLOps Pipeline for Loan Eligibility Prediction Model in Python on GCP

NLP Project for Beginners on Text Processing and Classification
This Project Explains the Basic Text Preprocessing and How to Build a Classification Model in Python

Langchain Project for Customer Support App in Python
In this LLM Project, you will learn how to enhance customer support interactions through Large Language Models (LLMs), enabling intelligent, context-aware responses. This Langchain project aims to seamlessly integrate LLM technology with databases, PDF knowledge bases, and audio processing agents to create a comprehensive customer support application.

Many-to-One LSTM for Sentiment Analysis and Text Generation
In this LSTM Project , you will build develop a sentiment detection model using many-to-one LSTMs for accurate prediction of sentiment labels in airline text reviews. Additionally, we will also train many-to-one LSTMs on 'Alice's Adventures in Wonderland' to generate contextually relevant text.

OpenCV Project for Beginners to Learn Computer Vision Basics
In this OpenCV project, you will learn computer vision basics and the fundamentals of OpenCV library using Python.

Text Classification with Transformers-RoBERTa and XLNet Model
In this machine learning project, you will learn how to load, fine tune and evaluate various transformer models for text classification tasks.