1 Reply Latest reply on Mar 22, 2016 6:21 AM by jon rios

    Count all values that are positive....

    jon rios

      i have a column of values, they are decimals (.245, -.013, .0023, etc), they have both positive value and negative values.  I want to count the values that are positive. It seems very basic but cant get the right syntax

       

      if (Return) > 0 THEN Count(Return) END

      if ATTR(Return) > 0 THEN Count(Return) END

       

      none of these works, can you please explain the correct way to do this.  The Excel equivalent =SUMIFS (RETURN , RETURN, ">0")

        • 1. Re: Count all values that are positive....
          Carl Slifer

          Howdy Jon!

           

          Try this

           

          SUM(IF Return > 0 THEN 1 ELSE 0 END)

          or

          COUNT(IF Return > 0 THEN 1  END)

           

          In the first one we look through every row and if the value is >0 we return 1 if not 0 and then we sum the total value. Well if 503 were greater than 0 we have 503 1's which will sum to 503.

          In the second one we are counting everytime something is greater than 0. It doesn't count when it is <=0 because we did not give it a value to use if it was <=0. When this happens Tableau treats the NULL values differently and ignores then in its count.

           

          Either should work but both can come out slightly differently in our view depending how we are using it. As a rule, I would personally use the SUM function.

           

          Cheers!

          Carl Slifer

          InterWorks