对满足特定要求的行进行计数,然后从另一个计数中减去该数字
Count rows that meet certain requirements and then subtract that number from another count
假设我有这样的数据:
Type
OrderNumber
Priority
DeliveryMethod
Boxes
1
High
UPS
Misc
1
High
UPS
Boxes
2
Standard
InstaBox
Boxes
3
Standard
UPS
Boxes
3
Standard
UPS
Boxes
3
Standard
UPS
Boxes
4
Standard
Instabox
Boxes
5
Standard
Instabox
Boxes
5
Standard
Instabox
Boxes
6
Standard
UPS
Boxes
7
Standard
UPS
而且我要统计所有所谓的“私人订单”。它们是具有唯一订单号、标准优先级和 UPS 交付的盒子。
(本例中有 2 个,6 和 7)
然后我想计算所有具有标准优先级的框并减去所有私人订单。 (有 9 个具有标准优先级的盒子,减去 2 个私人订单 = 7。)
这在 Tableau 中可行吗?我想在文本框中显示数字 7。
对于 Private orders
使用此字段
IF
{FIXED [Type], [Ordernumber] : COUNT([Ordernumber])} = 1
AND [Type] = 'Boxes' And [Priority] = 'Standard' And [DeliveryMethod] = 'UPS'
THEN 1 ELSE 0 END
所有盒子都使用这个
Sum(
If [Type] = 'Boxes' And [Priority] = 'Standard' then 1 else 0 end
)
所以对于最终输出,您可以直接使用这个 calculation2
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)
为了匹配模式,将上面的字段更改为 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)
使用的数据
结果
假设我有这样的数据:
Type | OrderNumber | Priority | DeliveryMethod |
---|---|---|---|
Boxes | 1 | High | UPS |
Misc | 1 | High | UPS |
Boxes | 2 | Standard | InstaBox |
Boxes | 3 | Standard | UPS |
Boxes | 3 | Standard | UPS |
Boxes | 3 | Standard | UPS |
Boxes | 4 | Standard | Instabox |
Boxes | 5 | Standard | Instabox |
Boxes | 5 | Standard | Instabox |
Boxes | 6 | Standard | UPS |
Boxes | 7 | Standard | UPS |
而且我要统计所有所谓的“私人订单”。它们是具有唯一订单号、标准优先级和 UPS 交付的盒子。 (本例中有 2 个,6 和 7) 然后我想计算所有具有标准优先级的框并减去所有私人订单。 (有 9 个具有标准优先级的盒子,减去 2 个私人订单 = 7。)
这在 Tableau 中可行吗?我想在文本框中显示数字 7。
对于 Private orders
使用此字段
IF
{FIXED [Type], [Ordernumber] : COUNT([Ordernumber])} = 1
AND [Type] = 'Boxes' And [Priority] = 'Standard' And [DeliveryMethod] = 'UPS'
THEN 1 ELSE 0 END
所有盒子都使用这个
Sum(
If [Type] = 'Boxes' And [Priority] = 'Standard' then 1 else 0 end
)
所以对于最终输出,您可以直接使用这个 calculation2
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)
为了匹配模式,将上面的字段更改为 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)
使用的数据
结果