0
votes

I have data within tableau that I wish to show a breakdown of USED and FREE storage. However, I need to first filter a specific column to perform 2 different types of calculations. Here is the data

        Total        Free              SKU    
     
        10           5                  A 
        20           1                  A
        5            4                  B
        2            0                  B
        10           5                  C
        10           6                  D

I am wanting to show a tableau bar chart that displays the available, used and total within Tableau. However, I need to first filter out by SKU:

I created this calculated field below as well as this calculated field:

Used = Total - Free

       IF CONTAINS(ATTR([SKU]),'A') or 
       CONTAINS(ATTR([SKU]),'D') 
       THEN SUM([Total]) 
       ELSEIF CONTAINS(ATTR([SKU]),'B') or 
       CONTAINS(ATTR([SKU]),'C') 
       THEN AVG([Total])
       END
     

This is what I have done so far, but not sure how to incorporate the calculated field within the viz

enter image description here

Any suggestion is appreciated.

1
I will update the post - Lynn
I am wanting the avail and used output as shown in the graph , but only after the filter is implemented. Right now, the graph is correct, however I need to include the if statement within it somehow . - Lynn
Right now, it’s only taking an average of the total. However, I wish it to only take an average for some, and to take a Sum for the others . I am just not sure how to achieve this in tableau. I will update the post - Lynn
Please update this post similar to previous one (by including desired output) and I'll try to solve it for you - AnilGoyal

1 Answers

1
votes

If I understand your problem correctly, proceed like this

Situation-1 You want to work at SKUG level

Create calculation fields each for total/USED/FREE as

SUM(ZN(IF CONTAINS([SKU], 'A') OR CONTAINS([SKU], 'D')
THEN [Total] END))
+
AVG(ZN(IF CONTAINS([SKU], 'B') OR CONTAINS([SKU], 'C')
THEN [Total] END))

Needless to say, please replace [total] by [used] or [free] as applicable

Situation-2 You want to work at higher level of detail instead. In this case you need to decide what you have to do with each of the SKU's group. Let's assume you want to add these. then creating similar fields will do. else replace + in a separate field with your desired operator(!).

Good luck!