简体   繁体   English

计算满足特定要求的行,然后从另一个计数中减去该数字

[英]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.

相关问题 Tableau - 计算最大数量 - Tableau - Count the maximum number 如果在 1 个字段或 Tablean 中的另一个字段中为“是”,则计数 - Count if "YES" in 1 field or another in Tablean Tableau count 列重复值的次数,按另外两列分组 - Tableau count number of times value repeated for the column, group by another two columns 如何计算Tableau中具有相同值的行 - How to count rows with the same value in Tableau 根据另一列计算出现次数并返回 label,每行具有最大计数 - Count occurence based on another column and return label having maximum count for each row 如何仅使用每个类别的特定行数进行计算? - How to use only certain number of rows per category for calculation? 如何计算某个维度使用了多少次 TABLEAU/SQL - How do I count how many times a certain dimension is used TABLEAU/SQL 有没有办法在粒度级别对不同的数字进行计数,以在画面中聚合多个条件? - Is there a way to count distinct number at granular level to aggregate level with multiple condition in tableau? 在 Tableau 中使用 COUNT 按组计算观察值 - Using COUNT in Tableau to count observations by group 如何计算 Tableau 中所有维度的空单元格总数? - How can I count the total number of empty cells across all dimensions in Tableau?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM