Bernard K

Nov 8, 2022

Guide to Nested IF Calculations in Tableau

Introduction

Nested IF statement, is simply an IF statement placed inside another IF statement. This logical function is useful when you want to test more than one condition (when you want to test one condition followed by another).

Syntax – Basic IF statement

IF <Logical test> THEN <Result_1>

ELSEIF <Logical test> THEN <Result_2>

……….

ELSE <Result_n>

END

Syntax – Nested IF Statement

IF <Logical test> THEN

IF <Logical test> THEN <Result_1> END

ELSEIF ……….

ELSE…………

END

Example of Nested IF calculation

Let’s say using the sample-superstore data set, you would like to populate the average time it took to ship products by Region and Ship Mode (for a past period).

This is how the current period might look like.

(Simple view showing the average time to ship products by Region and Ship Mode)

Assuming the past metrics are as follows.

You can populate the above metrics using this simple nested-if calculation.

Adding the above calculation to the view populates the past metrics as shown in the resulting view below.

(Notice the nested calculation has 5 IF statements and 5 END lines to mark the end of each if statement within the calculation)

Useful: Explore how to dynamically group and ungroup dimensions using nested if calculation

Useful: Explore Nested CASE-WHEN statement in Tableau

I hope this article was helpful to you. If you are interested in receiving more Tableau tips and tricks, kindly join our mailing list by subscribing below.

If you like the work we do and would like to work with us, drop us an email on our Contacts page and we’ll reach out!

Thank you for reading!