# Writing Conditions in Tableau

Version 3

Conditional Calculations:

If we want to use any calculation in the report and if which is not available at database, then we have to create that calculation with right syntax at tableau level.

And we use the Conditional Calculations for customization purpose.

For An Example: Sales less than 10 K is  "Worst Sales", >10 K and < 15 K is "Average" , >15 K and < 20 K is "Above Average" , >20 K and < 50 K is "Meet Target" , >50 K and < 75 K is "Excellent Sales."

Tableau Supports 2 Kind of Conditional Statements.

1) if

2) Case when

IF:

We can use IF conditional statement in 3 different cases.

1) IF THEN END  (If condition with 1 Possibility  without Else part)

2) IF THEN ELSE END  (IF [Condition Matches] then [Matched Value]  end)

3) IF THEN ELSEIF  ELSE END (IF [Condition Matches] then [Matched Value]  end)

1) IF THEN END  (If condition with 1 Possibility  without Else part)

EX: If  sum([Sales])>15000 then "Good"  end

Description: In the above example, If sales are more tan 15000 then those will be represented as "Good" (If condition matches then "Good" if Condition does not match then empty, i.e. null)

If Sales does not more then 15000 then those values are represented by empty since we did not define else part.

Next example will explains how out put will effect if we define else part.

2) IF THEN ELSE END  (IF [Condition Matches] then [Matched Value]  end)

If condition with 2 Possibilities including Else part

Syntax:

IF [Condition Matches] then [Matched Value] else [Non Matched Value]  end

EX: If  sum([Sales])>15000 then "Good" else "Average" end

Description:

In the above example, If sales are more tan 15000 then those will be represented as "Good" (If condition matches then "Good" if Condition does not match then empty, i.e. null)

If Sales does not more then 15000 then those values are represented by "Average" since we defined else part.

3) If then else - more than 2 Possibilities

if [Condition 1 Match] then [Value1]

elseif [Condition 2 Match] then [Value 2]

elseif [Condition 3 Match] then [Value 3]

elseif [Condition 4 Match] then [Value 4]

.....................

Else [Value N] end

EX:

If sum([Sales]) <15000 then "Below Average"

elseif  sum([Sales]) >=15000 and sum([Sales]) <25000 then "Average"

elseif  sum([Sales]) >=25000 and sum([Sales]) <50000 then "Above Average"

else "Excellent" end

=============================

Case <EXP>

when <Matches 1> then [Value 1]

when <Matches 2> then [Value 2]

when <Matches 3> then [Value 3]

Else [Value 4] end

Case [Region]

when "Central" then "Territory - 1"

when "East" then "Territory - 1"

else "Territory - 2" end