5 Replies Latest reply on Jun 25, 2018 1:38 PM by Amyl

    If statement with multiple conditions

    Amyl

      Hi Team,

       

       

      can some please help me how to achieve multiple conditions in if statement.

       

      i am writing below mentioned if statement but i am not achieving all, i am missing  "2-7 Days" .

       

       

      IF   DATEDIFF('day',[Ingestion Date],[max date])  > 29 THEN " 29 days"

       

      ELSEIF DATEDIFF('day',[Ingestion Date],[max date])  > 16 and

             DATEDIFF('day',[Ingestion Date],[max date])  < 29 THEN "15-28 Days"

       

      ELSEIF DATEDIFF('day',[Ingestion Date],[max date])  >9 and

             DATEDIFF('day',[Ingestion Date],[max date])  < 15 THEN "8-14 Days"

       

      ELSEIF DATEDIFF('day',[Ingestion Date],[max date])  > 3 and

             DATEDIFF('day',[Ingestion Date],[max date])  < 8  THEN "2-7 Days"

       

      ELSE "0-1 Days "    END

       

       

      Thank you

        • 1. Re: If statement with multiple conditions
          garth.conrad

          You data table has no values in that range. The '2-7 days' bucket category will not be created because there are no rows of data for it to be applied to.

           

          Here is the breakdown of the number of rows of data and the datediff value.

           

           

          G

          • 2. Re: If statement with multiple conditions
            Amyl

            Hi,

             

            If there is no values i should get  zero '0'. can you please give me the logic according to that.

             

            Thank you

            1 of 1 people found this helpful
            • 3. Re: If statement with multiple conditions
              garth.conrad

              I am sure there is someone else on the message board that can give a better answer but here is what I have done in the past in a similar situation.

               

              Your ‘buckets’ do not exist by themselves. Your calculated field assigns a bucket to each row of data in your data table. So the problem is that you have no rows of data that have “2-7 Days”, thus it does not show up in your bar chart. It is not a count of zero, it doesn’t exist at all. So the only way to change this is to add a new row to your data table that will result in a “2-7 Days” value. Although not ideal, in the past I have created an excel spreadsheet with a single column of data. That column contains the bucket names in each row, the same names you have in your calculation (e.g. 0-1 Days, 2-7 Days,....). You then import that spreadsheet into your Tableau workbook and join it to your main table using the ‘bucket‘ field and a full outer join (Must be full). That will add one row to your table for “2-7 Days” but that row has no other data in it. You may have to modify your method of counting (e.g. countd() on an id field or something) otherwise the ’number of records‘ field will show this as 1 for a count when there really is no data you want counted.

               

              G

              1 of 1 people found this helpful
              • 4. Re: If statement with multiple conditions
                Peter Fakan

                Just add an ifnull clause to your calculated field to return a 0 if there is a null response;

                 

                IF (ifnull( DATEDIFF('day',[Ingestion Date],[max date])  > 29 THEN " 29 days"),0)

                 

                HTH

                 

                Peter

                • 5. Re: If statement with multiple conditions
                  Amyl

                  Hi Can you please check this calculation,

                   

                  i am unable to execute, please check twbx file for more information.

                   

                  Thank you