5 Replies Latest reply on Jun 10, 2016 2:53 AM by Ashish Chaudhari

# Convert String into Integer

Dear All,

I am new to tableau and trying to convert a string into integer:

For example: "Agree" or "Strongly agree" to be converted into integer value 1.

I tried IF, case and replace statements but it tells me that all the fields have to be strings!

Ideas?

• ###### 1. Re: Convert String into Integer

If [String] = 'Agree' or [String] = 'Strongly Agree' then 1 else 0 end should work.

• ###### 2. Re: Convert String into Integer

Many thanks for that Pooja, much appreciated.

I was wondering if there is any chance to apply that over many columns at once?

For example:

Question1      Question2          Calculation

Agree               Agree               2

Agree               Disagree          1

• ###### 3. Re: Convert String into Integer

If you want to do it do multiple columns then there will be combination of values comes in to picture.

Considering Agree ad Disagree as valies following cases can be drafted.

You will have to write below formula to get the desired result which you have suggested in previous post. Please check and confirm the output attached below. Let me know if that what you are looking for.

Calculated field used.

if [Question 1]="Agree" and [Question 2]="Agree" THEN 2

ELSEIF  [Question 1]="Agree" and [Question 2]="Disagree" THEN 1

ELSEIF  [Question 1]="Disagree" and [Question 2]="Agree" THEN 1

ELSEIF  [Question 1]="Disagree" and [Question 2]="Disagree" THEN 0

END

Also attaching the the tableau workbook for the same.

Thanks and Regards,

Ashish Chaudhari

• ###### 4. Re: Convert String into Integer

Thanks for the reply, but my data varies and looks like attached.

Basically the data should reflect the percentage of the students response for each faculty, were agree and disagree are considered as "1" state and the rest is 0.

For example, if I take the first 3 questions in my dataset, the percentage of the business faculty is 0.6667. (this has been calculated as: (questions answered as agree or strongly agree) / (total answered questions).

I am trying to write down different commands, but looks like Tableau takes just 1 command line. Also, I tried to use IF statement to include various commands, but got an error saying I cannot mix aggregate and non-aggregate conditions or values.

 Student name Faculty program campus Q1 Q2 Q3 Q4 Q5 Q6 Ahmad Fost CS Mt Helen Agree Strongly Agree Agree Agree Strongly Agree Strongly Agree Mohammed Fost CS Mt helen Strongly Agree Strongly Agree Agree Strongly Agree Agree Agree Belal Fost CS MIT Sydney Strongly Agree Agree Strongly Agree Agree Strongly Agree Agree Hamzeh Fost CS MIT Melbourne Strongly Agree Strongly Agree Agree Strongly Agree Agree Don’t Agree Shaker Fost CE Mt Helen Agree Don’t Agree Agree Don’t Agree Don’t Agree Strongly Agree Salameh Business Basic MIT Sydney Agree Don’t Agree Agree Don’t Agree Don’t Agree Strongly Agree Mamoun Business Basic Mt Helen Don’t Agree Agree Strongly Agree Agree Agree Don’t Agree Moutaz Business Intermediate MIT Melbourne Agree Don’t Agree Don’t Agree Agree Don’t Agree Agree Ammar Business Intermediate Mt Helen Strongly Agree Strongly Agree Agree Strongly Agree Agree Don’t Agree

• ###### 5. Re: Convert String into Integer

Please find the attached workbook and please confirm the output attached below.

% by Faculty for Q1,Q2 and Q3

% by Faculty for Q1,Q2, Q3, Q4 and Q5

Thanks and Regards,

Ashish Chaudhari