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 ffdfd
• 5,550 points
1,614 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 28, 2018 by ffdfd
@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 17, 2018 in Tableau by ffdfd
• 5,550 points
654 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, 2019 in Tableau by anonymous
• 33,030 points
725 views
+2 votes
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 ffdfd
• 5,550 points
1,206 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 ffdfd
• 5,550 points
1,187 views
0 votes
2 answers

Calculation issue: Distinct sum in Tableau

I feel the easiest way is to ...READ MORE

answered Aug 26, 2020 in Tableau by Dhiraj Kumar Sahu
9,614 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 18, 2018 in Tableau by ffdfd
• 5,550 points
710 views
0 votes
1 answer

Tableau charts with calculated field

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

answered Jul 19, 2018 in Tableau by Atul
• 10,240 points
726 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 25, 2018 in Tableau by Atul
• 10,240 points
7,676 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP