6 Replies Latest reply on Feb 11, 2019 6:54 AM by Jim Dehner

    Calculation with IF statement

    Linda Toca

      Hi all,

      I'm quite fresh in Tableau, and I can't figure out this relatively simple equation.


      All I need to do is create calculated fields for different categories and get the counts for each category, for example sum of counts of "Apples":

      Sum(IF[store1]="Apple" THEN [Store1 Count]END)+Sum(IF[Store2]="Apple" THEN [Store2 Count]END)+Sum(IF[Store3]="Apple" THEN [Store3 Count]END)+Sum(IF[Store4]="Apple" THEN [Store4 Count]END)+Sum(IF[Store5]="Apple" THEN [Store5 Count]END)

      But it works only when a column actually has a value, but if a there's a column with no value the SUM of the equation becomes 0.

      I know this must be very simple, I just can't figure it out.



      I have made a test sample that represents the data I have:


      idstore1store1_countstore2store2_countstore3store3_countstore4store4_countstore5store5_counttotal count
      2Orange3Banana2Orange Pear510
      3Banana5Pear8Apple Banana4 17
      4Pear10Banana5Orange Banana419


      Thank you!