简体   繁体   中英

Implementing a calculated field within my Tableau Viz

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

在此处输入图片说明

Any suggestion is appreciated.

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!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM