简体   繁体   English

在我的 Tableau Viz 中实现计算字段

[英]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.我在 tableau 中有数据,我希望显示使用和免费存储的细分。 However, I need to first filter a specific column to perform 2 different types of calculations.但是,我需要先过滤特定列以执行 2 种不同类型的计算。 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.我想显示一个表格条形图,显示 Tableau 中的可用、已用和总数。 However, I need to first filter out by SKU:但是,我需要先按 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情况 1你想在 SKUG 级别工作

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不用说,请根据情况将[total]替换为[used][free]

Situation-2 You want to work at higher level of detail instead.情况 2您想要在更高的细节级别上工作。 In this case you need to decide what you have to do with each of the SKU's group.在这种情况下,您需要决定如何处理每个 SKU 组。 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!祝你好运!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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