Calculated filed with if-then

0 votes

I am working on creating some calculated fields

The data for the "test2" field is imported from Access consists of numbers or "Null" in text.

I also have fields "test1" and "minimum" and "maximum" where all the three parameters are numbers.

I would like to create a calculated field with an if statement.

I would like to do the following:

  1. If "test2" is not "Null" and "test2" < "minimum" then calculate "minimum" - "test2". (I was using the syntax IIF and != for not equal, but it did not like it because "Null" is a string value)
  2. else if "test2" is not "Null" and "test1" < "minimum" then calculate "minimum" - "test1"

How should I create this calculated field? Please advise.

Mar 27, 2018 in Tableau by Atul
• 5,530 points
61 views

1 answer to this question.

+1 vote
Best answer

Below is the required code: 

IF (NOT ISNULL([test2])) AND [test2] < [minimum]
THEN [minimum] - [test2]
ELSEIF (NOT ISNULL([test2])) AND [test1] < [minimum]
THEN [minimum] - [test1]
END

I guess ISNULL is the part where you got stuck. You can check out this link to learn more on ISNULL.

answered Mar 27, 2018 by Atul
• 10,240 points

selected Mar 27, 2018 by Atul
@Grim Thankyou for answering my query and giving additional useful resources for learning. This set of code worked for me.

Related Questions In Tableau

0 votes
0 answers

Creating a multiple charts with calculated field

Sample data: Table Name: A Mode Country Month Visitor ...READ MORE

Aug 16, 2018 in Tableau by Atul
• 5,530 points
40 views
0 votes
1 answer

How to perform a calculation using one variable with an aggregation in calculated field?

Hi, You can use the calculative field and ...READ MORE

answered May 20 in Tableau by anonymous
• 19,510 points
24 views
+1 vote
1 answer
+2 votes
1 answer
0 votes
1 answer

How to calculate profit when cost and revenue are in same column?

You can create the following calculated fields: Profit: SUM(IIF([account_category] ...READ MORE

answered Apr 10, 2018 in Tableau by Atul
• 5,530 points
65 views
0 votes
1 answer

Creating a calculated field with LOD expression

Go ahead and try the following three ...READ MORE

answered Apr 20, 2018 in Tableau by Atul
• 5,530 points
80 views
0 votes
1 answer

Calculation issue: Distinct sum in Tableau

SUM( { FIXED [Brand], [Market]: AVG(Target) } ...READ MORE

answered May 8, 2018 in Tableau by Atul
• 10,240 points
2,159 views
0 votes
1 answer

Creating a calculated field for summing up the values

Well you can use this in your ...READ MORE

answered May 17, 2018 in Tableau by Atul
• 5,530 points
36 views
0 votes
1 answer

Tableau charts with calculated field

I could get Visitor Rate = COUNTD(Visitor ...READ MORE

answered Jul 18, 2018 in Tableau by Atul
• 10,240 points
32 views
0 votes
1 answer

How to combine rows with same information in Tableau

@Ghost, Tableau has a function RANK_UNIQUE which you ...READ MORE

answered May 24, 2018 in Tableau by Atul
• 10,240 points
755 views