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

    Convert String into Integer

    Ahmad Azab

      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
          pooja.gandhi

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

          • 2. Re: Convert String into Integer
            Ahmad Azab

            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
              Ashish Chaudhari

              Hi Ahmad,

               

              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
                Ahmad Azab

                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 nameFacultyprogramcampusQ1Q2Q3Q4Q5Q6
                AhmadFostCSMt HelenAgreeStrongly AgreeAgreeAgreeStrongly AgreeStrongly Agree
                MohammedFostCSMt helenStrongly AgreeStrongly AgreeAgreeStrongly AgreeAgreeAgree
                BelalFostCSMIT SydneyStrongly AgreeAgreeStrongly AgreeAgreeStrongly AgreeAgree
                HamzehFostCSMIT MelbourneStrongly AgreeStrongly AgreeAgreeStrongly AgreeAgreeDon’t Agree
                ShakerFostCEMt HelenAgreeDon’t AgreeAgreeDon’t AgreeDon’t AgreeStrongly Agree
                SalamehBusinessBasicMIT SydneyAgreeDon’t AgreeAgreeDon’t AgreeDon’t AgreeStrongly Agree
                MamounBusinessBasicMt HelenDon’t AgreeAgreeStrongly AgreeAgreeAgreeDon’t Agree
                MoutazBusinessIntermediateMIT MelbourneAgreeDon’t AgreeDon’t AgreeAgreeDon’t AgreeAgree
                AmmarBusinessIntermediateMt HelenStrongly AgreeStrongly AgreeAgreeStrongly AgreeAgreeDon’t Agree

                Thanks in advance

                • 5. Re: Convert String into Integer
                  Ashish Chaudhari

                  Hi Ahmad,

                   

                  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