[英]Count rows that meet certain requirements and then subtract that number from another count
Let's say I have data like this:假设我有这样的数据:
Type类型 | OrderNumber订单号 | Priority优先 | DeliveryMethod运输方式 |
---|---|---|---|
Boxes盒子 | 1 1 | High高的 | UPS UPS |
Misc杂项 | 1 1 | High高的 | UPS UPS |
Boxes盒子 | 2 2 | Standard标准 | InstaBox InstaBox |
Boxes盒子 | 3 3 | Standard标准 | UPS UPS |
Boxes盒子 | 3 3 | Standard标准 | UPS UPS |
Boxes盒子 | 3 3 | Standard标准 | UPS UPS |
Boxes盒子 | 4 4 | Standard标准 | Instabox Instabox |
Boxes盒子 | 5 5 | Standard标准 | Instabox Instabox |
Boxes盒子 | 5 5 | Standard标准 | Instabox Instabox |
Boxes盒子 | 6 6 | Standard标准 | UPS UPS |
Boxes盒子 | 7 7 | Standard标准 | UPS UPS |
And I want to count all the so called "Private Orders".我想计算所有所谓的“私人订单”。 They are boxes with an unique ordernumber and a Standard priority and UPS delivery.它们是具有唯一订单号和标准优先级和 UPS 交付的箱子。 (There's 2 in this example, 6 and 7) Then I want to count all the boxes with Standard priority and subtract all the Private orders. (本例中有 2 个,6 和 7)然后我想计算所有具有标准优先级的框并减去所有私人订单。 (There's 9 boxes with Standard priority, minus the 2 Private orders = 7.) (有 9 个具有标准优先级的盒子,减去 2 个私人订单 = 7。)
Is that possible in Tableau?这在 Tableau 中可行吗? I want to display the number 7 in a textbox.我想在文本框中显示数字 7。
For Private orders
use this field对于Private orders
请使用此字段
IF
{FIXED [Type], [Ordernumber] : COUNT([Ordernumber])} = 1
AND [Type] = 'Boxes' And [Priority] = 'Standard' And [DeliveryMethod] = 'UPS'
THEN 1 ELSE 0 END
For all boxes use this对于所有盒子都使用这个
Sum(
If [Type] = 'Boxes' And [Priority] = 'Standard' then 1 else 0 end
)
SO FOR FINAL OUTPUT YOU MAY USE THIS DIRECTLY say calculation2
所以对于最终的 OUTPUT 你可以直接用这个说calculation2
2
Sum(
If [Type] = 'BOXES' And [Priority] = 'Standard' then 1 else 0 END
) -
Sum(IF
{FIXED [Type], [OrderNumber] : COUNT([OrderNumber])} = 1
AND [Type] = 'BOXES' And [Priority] = 'Standard' And [DeliveryMethod] = 'UPS'
THEN 1 ELSE 0 END)
For matching pattern change the above field to say calculation3
对于匹配模式,将上述字段更改为calculation3
Sum(
If [Type] = 'BOXES' And [Priority] = 'Standard' then 1 else 0 END
) -
Sum(IF
{FIXED [Type], [OrderNumber] : COUNT([OrderNumber])} = 1
AND [Type] = 'BOXES' And [Priority] = 'Standard' And REGEXP_MATCH([DeliveryMethod], "UPS")
THEN 1 ELSE 0 END)
the data used使用的数据
Results结果
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.