5 Replies Latest reply on Nov 25, 2016 2:34 AM by Dilyana Suleymanova

    Question to "IF" formula

    Dilyana Suleymanova

      Hi there

      thi is my data set



      Contact results     ID

      Call                         1234

      Email                       5677

      Call                         7897   

      Call                         6780   

      Fax                         5678

      Call                         2456   


      I would like to count all ID if the result = Calls and this is my formula:


      If [Contact results] = "Call" then countd [ID]



      Unfortunately it doesn't work. I don't know why. Any ideas?





        • 1. Re: Question to "IF" formula
          Chris Geatch

          It's not clear exactly what you're trying to do.  If you drag Contact Results on to Rows, and Number of Records into the table, then you will get the counts for each type of contact result.


          If you only want the count to be done when the Contact Result is Call, then you can use a formula like

          SUM(IF [Contact Results] = "Call" Then 1 else 0 end)


          If you always want the value to the count of Calls no matter what you're looking at, then you can use something like

          {FIXED :SUM(IF [Contact Results]="Call" then 1 else 0 END)}


          The 3 methods give the result below.

          I see you've used COUNTD, but you don't have any duplicate IDs.  If there are duplicate IDs then the methods above are too simple.  Maybe if you can explain the context of what you're trying to do, someone can give a more helpful answer.

          2 of 2 people found this helpful
          • 2. Re: Question to "IF" formula
            chris monger

            Hi DS,

            For the formula there text should be surrounded by single quotes to identify, so should be

                 [Contact results] = 'Call'


            As for the full calculation there's a couple of ways to do this.


            The most straightforward is to have the calculated field as

                 IF ([Contact results]) = 'Call' then [ID] end

            and set the measure calculation in the shelf to CountD.


            If you did want to do it all in the calculated field you can have the formula as

                      COUNTD(IF ([Contact results]) = 'Call' then [ID] end)



            2 of 2 people found this helpful
            • 3. Re: Question to "IF" formula
              Rudranshu Praharaj

              Hi Dilyana,


              You cannot mix aggregate & non-aggregate comparison in a if statement. The countd function here is an aggregation & hence cannot be used with a non-aggregate field contact result.


              Instead use this

              ATTR([Contact results]) = "Call" then countd [ID]


              I am attaching the Tableau workbook for your reference. Refer to the field Count ID.


              Mark the answer correct if you find it helpful.



              Rudranshu Praharaj

              1 of 1 people found this helpful
              • 4. Re: Question to "IF" formula
                Mahfooj Khan

                Already you've received different solutions. However a small addition to your calculated field result the expected output. Use ATTR() function outside of your Contact field.


                If ATTR([Contact results]) = "Call" then COUNTD([ID])




                2 of 2 people found this helpful
                • 5. Re: Question to "IF" formula
                  Dilyana Suleymanova

                  HI guys, thank you so much!!!!

                  Best regards from Berlin